summaryrefslogtreecommitdiff
path: root/chromium/chrome/renderer/media/flash_embed_rewrite_unittest.cc
blob: 48ef65a18fa50c4843e5835f115c8bbb5632160e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/renderer/media/flash_embed_rewrite.h"

#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"

TEST(FlashEmbedRewriteTest, YouTubeRewriteEmbed) {
  struct TestData {
    std::string original;
    std::string expected;
  } test_data[] = {
      // { original, expected }
      {"http://youtube.com", ""},
      {"http://www.youtube.com", ""},
      {"https://www.youtube.com", ""},
      {"http://www.foo.youtube.com", ""},
      {"https://www.foo.youtube.com", ""},
      // Non-YouTube domains shouldn't be modified
      {"http://www.plus.google.com", ""},
      // URL isn't using Flash
      {"http://www.youtube.com/embed/deadbeef", ""},
      // URL isn't using Flash, no www
      {"http://youtube.com/embed/deadbeef", ""},
      // URL isn't using Flash, invalid parameter construct
      {"http://www.youtube.com/embed/deadbeef&start=4", ""},
      // URL is using Flash, no www
      {"http://youtube.com/v/deadbeef", "http://youtube.com/embed/deadbeef"},
      // URL is using Flash, is valid, https
      {"https://www.youtube.com/v/deadbeef",
       "https://www.youtube.com/embed/deadbeef"},
      // URL is using Flash, is valid, http
      {"http://www.youtube.com/v/deadbeef",
       "http://www.youtube.com/embed/deadbeef"},
      // URL is using Flash, valid
      {"https://www.foo.youtube.com/v/deadbeef",
       "https://www.foo.youtube.com/embed/deadbeef"},
      // URL is using Flash, is valid, has one parameter
      {"http://www.youtube.com/v/deadbeef?start=4",
       "http://www.youtube.com/embed/deadbeef?start=4"},
      // URL is using Flash, is valid, has multiple parameters
      {"http://www.youtube.com/v/deadbeef?start=4&fs=1",
       "http://www.youtube.com/embed/deadbeef?start=4&fs=1"},
      // URL is using Flash, invalid parameter construct, has one parameter
      {"http://www.youtube.com/v/deadbeef&start=4",
       "http://www.youtube.com/embed/deadbeef?start=4"},
      // URL is using Flash, invalid parameter construct, has multiple
      // parameters
      {"http://www.youtube.com/v/deadbeef&start=4&fs=1?foo=bar",
       "http://www.youtube.com/embed/deadbeef?start=4&fs=1&foo=bar"},
      // URL is using Flash, invalid parameter construct, has multiple
      // parameters
      {"http://www.youtube.com/v/deadbeef&start=4&fs=1",
       "http://www.youtube.com/embed/deadbeef?start=4&fs=1"},
      // Invalid parameter construct
      {"http://www.youtube.com/abcd/v/deadbeef", ""},
      // Invalid parameter construct
      {"http://www.youtube.com/v/abcd/", "http://www.youtube.com/embed/abcd/"},
      // Invalid parameter construct
      {"http://www.youtube.com/v/123/", "http://www.youtube.com/embed/123/"},
      // youtube-nocookie.com
      {"http://www.youtube-nocookie.com/v/123/",
       "http://www.youtube-nocookie.com/embed/123/"},
      // youtube-nocookie.com, isn't using flash
      {"http://www.youtube-nocookie.com/embed/123/", ""},
      // youtube-nocookie.com, has one parameter
      {"http://www.youtube-nocookie.com/v/123?start=foo",
       "http://www.youtube-nocookie.com/embed/123?start=foo"},
      // youtube-nocookie.com, has multiple parameters
      {"http://www.youtube-nocookie.com/v/123?start=foo&bar=baz",
       "http://www.youtube-nocookie.com/embed/123?start=foo&bar=baz"},
      // youtube-nocookie.com, invalid parameter construct, has one parameter
      {"http://www.youtube-nocookie.com/v/123&start=foo",
       "http://www.youtube-nocookie.com/embed/123?start=foo"},
      // youtube-nocookie.com, invalid parameter construct, has multiple
      // parameters
      {"http://www.youtube-nocookie.com/v/123&start=foo&bar=baz",
       "http://www.youtube-nocookie.com/embed/123?start=foo&bar=baz"},
      // youtube-nocookie.com, https
      {"https://www.youtube-nocookie.com/v/123/",
       "https://www.youtube-nocookie.com/embed/123/"},
      // URL isn't using Flash, has JS API enabled
      {"http://www.youtube.com/embed/deadbeef?enablejsapi=1", ""},
      // URL is using Flash, has JS API enabled
      {"http://www.youtube.com/v/deadbeef?enablejsapi=1",
       "http://www.youtube.com/embed/deadbeef?enablejsapi=1"},
      // youtube-nocookie.com, has JS API enabled
      {"http://www.youtube-nocookie.com/v/123?enablejsapi=1",
       "http://www.youtube-nocookie.com/embed/123?enablejsapi=1"},
      // ... with multiple parameters.
      {"http://www.youtube.com/v/deadbeef?enablejsapi=1&foo=2",
       "http://www.youtube.com/embed/deadbeef?enablejsapi=1&foo=2"},
      // URL is using Flash, has JS API enabled, invalid parameter construct
      {"http://www.youtube.com/v/deadbeef&enablejsapi=1",
       "http://www.youtube.com/embed/deadbeef?enablejsapi=1"},
      // ... with multiple parameters.
      {"http://www.youtube.com/v/deadbeef&enablejsapi=1&foo=2",
       "http://www.youtube.com/embed/deadbeef?enablejsapi=1&foo=2"},
      // URL is using Flash, has JS API enabled, invalid parameter construct,
      // has multiple parameters
      {"http://www.youtube.com/v/deadbeef&start=4&enablejsapi=1",
       "http://www.youtube.com/embed/deadbeef?start=4&enablejsapi=1"},
  };

  for (const auto& data : test_data) {
    EXPECT_EQ(GURL(data.expected),
              FlashEmbedRewrite::RewriteFlashEmbedURL(GURL(data.original)));
  }
}

TEST(FlashEmbedRewriteTest, DailymotionRewriteEmbed) {
  struct TestData {
    std::string original;
    std::string expected;
  } test_data[] = {
      // { original, expected }
      {"http://dailymotion.com", ""},
      {"http://www.dailymotion.com", ""},
      {"https://www.dailymotion.com", ""},
      {"http://www.foo.dailymotion.com", ""},
      {"https://www.foo.dailymotion.com", ""},
      // URL isn't using Flash
      {"http://www.dailymotion.com/embed/video/deadbeef", ""},
      // URL isn't using Flash, no www
      {"http://dailymotion.com/embed/video/deadbeef", ""},
      // URL isn't using Flash, invalid parameter construct
      {"http://www.dailymotion.com/embed/video/deadbeef&start=4", ""},
      // URL is using Flash, no www
      {"http://dailymotion.com/swf/deadbeef",
       "http://dailymotion.com/embed/video/deadbeef"},
      // URL is using Flash, is valid, https
      {"https://www.dailymotion.com/swf/deadbeef",
       "https://www.dailymotion.com/embed/video/deadbeef"},
      // URL is using Flash, is valid, http
      {"http://www.dailymotion.com/swf/deadbeef",
       "http://www.dailymotion.com/embed/video/deadbeef"},
      // URL is using Flash, valid
      {"https://www.foo.dailymotion.com/swf/deadbeef",
       "https://www.foo.dailymotion.com/embed/video/deadbeef"},
      // URL is using Flash, is valid, has one parameter
      {"http://www.dailymotion.com/swf/deadbeef?start=4",
       "http://www.dailymotion.com/embed/video/deadbeef?start=4"},
      // URL is using Flash, is valid, has multiple parameters
      {"http://www.dailymotion.com/swf/deadbeef?start=4&fs=1",
       "http://www.dailymotion.com/embed/video/deadbeef?start=4&fs=1"},
      // URL is using Flash, invalid parameter construct, has one parameter
      {"http://www.dailymotion.com/swf/deadbeef&start=4",
       "http://www.dailymotion.com/embed/video/deadbeef&start=4"},
      // Invalid URL.
      {"http://www.dailymotion.com/abcd/swf/deadbeef", ""},
      // Uses /swf/video/
      {"http://www.dailymotion.com/swf/video/deadbeef",
       "http://www.dailymotion.com/embed/video/deadbeef"}};

  for (const auto& data : test_data) {
    EXPECT_EQ(GURL(data.expected),
              FlashEmbedRewrite::RewriteFlashEmbedURL(GURL(data.original)));
  }
}