| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <map> | 5 #include <map> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #import <EarlGrey/EarlGrey.h> | 8 #import <EarlGrey/EarlGrey.h> |
| 9 | 9 |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| 11 #import "base/test/ios/wait_util.h" | 11 #import "base/test/ios/wait_util.h" |
| 12 #import "ios/web/public/test/http_server/http_server.h" | 12 #import "ios/web/public/test/http_server/http_server.h" |
| 13 #include "ios/web/public/test/http_server/http_server_util.h" | 13 #include "ios/web/public/test/http_server/http_server_util.h" |
| 14 #import "ios/web/shell/test/earl_grey/shell_earl_grey.h" | 14 #import "ios/web/shell/test/earl_grey/shell_earl_grey.h" |
| 15 #import "ios/web/shell/test/earl_grey/shell_matchers.h" | 15 #import "ios/web/shell/test/earl_grey/shell_matchers.h" |
| 16 #import "ios/web/shell/test/earl_grey/web_shell_test_case.h" | 16 #import "ios/web/shell/test/earl_grey/web_shell_test_case.h" |
| 17 #include "url/gurl.h" | 17 #include "url/gurl.h" |
| 18 | 18 |
| 19 #if !defined(__has_feature) || !__has_feature(objc_arc) | 19 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 20 #error "This file requires ARC support." | 20 #error "This file requires ARC support." |
| 21 #endif | 21 #endif |
| 22 | 22 |
| 23 using web::WebViewContainingText; | |
| 24 using web::WebViewCssSelector; | 23 using web::WebViewCssSelector; |
| 25 | 24 |
| 26 namespace { | 25 namespace { |
| 27 | 26 |
| 28 // Loads a web page with given content. | 27 // Loads a web page with given content. |
| 29 void LoadPage(const std::string& page_content) { | 28 void LoadPage(const std::string& page_content) { |
| 30 const GURL url = web::test::HttpServer::MakeUrl("http://plugin"); | 29 const GURL url = web::test::HttpServer::MakeUrl("http://plugin"); |
| 31 std::map<GURL, std::string> responses{{url, page_content}}; | 30 std::map<GURL, std::string> responses{{url, page_content}}; |
| 32 web::test::SetUpSimpleHttpServer(responses); | 31 web::test::SetUpSimpleHttpServer(responses); |
| 33 [ShellEarlGrey loadURL:url]; | 32 [ShellEarlGrey loadURL:url]; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 50 "<html><body width='800' height='600'>" | 49 "<html><body width='800' height='600'>" |
| 51 "<p>%s</p>" | 50 "<p>%s</p>" |
| 52 "<applet code='Some.class' width='550' height='550'>" | 51 "<applet code='Some.class' width='550' height='550'>" |
| 53 " <p>%s</p>" | 52 " <p>%s</p>" |
| 54 "</applet>" | 53 "</applet>" |
| 55 "</body></html>", | 54 "</body></html>", |
| 56 kPageDescription, kFallbackText); | 55 kPageDescription, kFallbackText); |
| 57 LoadPage(page); | 56 LoadPage(page); |
| 58 | 57 |
| 59 // Verify that placeholder image is not displayed. | 58 // Verify that placeholder image is not displayed. |
| 60 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kPageDescription)] | 59 [ShellEarlGrey waitForWebViewContainingText:kPageDescription]; |
| 61 assertWithMatcher:grey_notNil()]; | 60 [ShellEarlGrey waitForWebViewContainingText:kFallbackText]; |
| 62 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kFallbackText)] | |
| 63 assertWithMatcher:grey_notNil()]; | |
| 64 [[EarlGrey selectElementWithMatcher:WebViewCssSelector("img")] | 61 [[EarlGrey selectElementWithMatcher:WebViewCssSelector("img")] |
| 65 assertWithMatcher:grey_nil()]; | 62 assertWithMatcher:grey_nil()]; |
| 66 } | 63 } |
| 67 | 64 |
| 68 // Tests placeholder for a large <applet> with no fallback. | 65 // Tests placeholder for a large <applet> with no fallback. |
| 69 - (void)testPluginPlaceholderAppletOnly { | 66 - (void)testPluginPlaceholderAppletOnly { |
| 70 const char kPageDescription[] = "Applet, no fallback"; | 67 const char kPageDescription[] = "Applet, no fallback"; |
| 71 const std::string page = base::StringPrintf( | 68 const std::string page = base::StringPrintf( |
| 72 "<html><body width='800' height='600'>" | 69 "<html><body width='800' height='600'>" |
| 73 "<p>%s</p>" | 70 "<p>%s</p>" |
| 74 "<applet code='Some.class' width='550' height='550'>" | 71 "<applet code='Some.class' width='550' height='550'>" |
| 75 "</applet>" | 72 "</applet>" |
| 76 "</body></html>", | 73 "</body></html>", |
| 77 kPageDescription); | 74 kPageDescription); |
| 78 LoadPage(page); | 75 LoadPage(page); |
| 79 | 76 |
| 80 // Verify that plugin object is replaced with placeholder image. | 77 // Verify that plugin object is replaced with placeholder image. |
| 81 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kPageDescription)] | 78 [ShellEarlGrey waitForWebViewContainingText:kPageDescription]; |
| 82 assertWithMatcher:grey_notNil()]; | |
| 83 [[EarlGrey selectElementWithMatcher:WebViewCssSelector("img[src*='data']")] | 79 [[EarlGrey selectElementWithMatcher:WebViewCssSelector("img[src*='data']")] |
| 84 assertWithMatcher:grey_notNil()]; | 80 assertWithMatcher:grey_notNil()]; |
| 85 } | 81 } |
| 86 | 82 |
| 87 // Tests placeholder for a large <object> with an embed fallback. | 83 // Tests placeholder for a large <object> with an embed fallback. |
| 88 - (void)testPluginPlaceholderObjectEmbed { | 84 - (void)testPluginPlaceholderObjectEmbed { |
| 89 const char kPageDescription[] = "Object, embed fallback"; | 85 const char kPageDescription[] = "Object, embed fallback"; |
| 90 const std::string page = base::StringPrintf( | 86 const std::string page = base::StringPrintf( |
| 91 "<html><body width='800' height='600'>" | 87 "<html><body width='800' height='600'>" |
| 92 "<p>%s</p>" | 88 "<p>%s</p>" |
| 93 "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'" | 89 "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'" |
| 94 " codebase='http://download.macromedia.com/pub/shockwave/cabs/'" | 90 " codebase='http://download.macromedia.com/pub/shockwave/cabs/'" |
| 95 "flash/swflash.cab#version=6,0,0,0' width='550' height='550'>" | 91 "flash/swflash.cab#version=6,0,0,0' width='550' height='550'>" |
| 96 " <param name='movie' value='some.swf'>" | 92 " <param name='movie' value='some.swf'>" |
| 97 " <embed src='some.swf' width='550' height='550'>" | 93 " <embed src='some.swf' width='550' height='550'>" |
| 98 "</object>" | 94 "</object>" |
| 99 "</body></html>", | 95 "</body></html>", |
| 100 kPageDescription); | 96 kPageDescription); |
| 101 LoadPage(page); | 97 LoadPage(page); |
| 102 | 98 |
| 103 // Verify that plugin object is replaced with placeholder image. | 99 // Verify that plugin object is replaced with placeholder image. |
| 104 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kPageDescription)] | 100 [ShellEarlGrey waitForWebViewContainingText:kPageDescription]; |
| 105 assertWithMatcher:grey_notNil()]; | |
| 106 [[EarlGrey selectElementWithMatcher:WebViewCssSelector("img[src*='data']")] | 101 [[EarlGrey selectElementWithMatcher:WebViewCssSelector("img[src*='data']")] |
| 107 assertWithMatcher:grey_notNil()]; | 102 assertWithMatcher:grey_notNil()]; |
| 108 } | 103 } |
| 109 | 104 |
| 110 // Tests that a large <object> with text fallback is untouched. | 105 // Tests that a large <object> with text fallback is untouched. |
| 111 - (void)testPluginPlaceholderObjectFallback { | 106 - (void)testPluginPlaceholderObjectFallback { |
| 112 const char kPageDescription[] = "Object, text fallback"; | 107 const char kPageDescription[] = "Object, text fallback"; |
| 113 const char kFallbackText[] = "You don't have Flash. Tough luck!"; | 108 const char kFallbackText[] = "You don't have Flash. Tough luck!"; |
| 114 const std::string page = base::StringPrintf( | 109 const std::string page = base::StringPrintf( |
| 115 "<html><body width='800' height='600'>" | 110 "<html><body width='800' height='600'>" |
| 116 "<p>%s</p>" | 111 "<p>%s</p>" |
| 117 "<object type='application/x-shockwave-flash' data='some.sfw'" | 112 "<object type='application/x-shockwave-flash' data='some.sfw'" |
| 118 " width='550' height='550'>" | 113 " width='550' height='550'>" |
| 119 " <param name='movie' value='some.swf'>" | 114 " <param name='movie' value='some.swf'>" |
| 120 " <p>%s</p>" | 115 " <p>%s</p>" |
| 121 "</object>" | 116 "</object>" |
| 122 "</body></html>", | 117 "</body></html>", |
| 123 kPageDescription, kFallbackText); | 118 kPageDescription, kFallbackText); |
| 124 LoadPage(page); | 119 LoadPage(page); |
| 125 | 120 |
| 126 // Verify that placeholder image is not displayed. | 121 // Verify that placeholder image is not displayed. |
| 127 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kPageDescription)] | 122 [ShellEarlGrey waitForWebViewContainingText:kPageDescription]; |
| 128 assertWithMatcher:grey_notNil()]; | 123 [ShellEarlGrey waitForWebViewContainingText:kFallbackText]; |
| 129 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kFallbackText)] | |
| 130 assertWithMatcher:grey_notNil()]; | |
| 131 [[EarlGrey selectElementWithMatcher:WebViewCssSelector("img")] | 124 [[EarlGrey selectElementWithMatcher:WebViewCssSelector("img")] |
| 132 assertWithMatcher:grey_nil()]; | 125 assertWithMatcher:grey_nil()]; |
| 133 } | 126 } |
| 134 | 127 |
| 135 // Tests placeholder for a large <object> with no fallback. | 128 // Tests placeholder for a large <object> with no fallback. |
| 136 - (void)testPluginPlaceholderObjectOnly { | 129 - (void)testPluginPlaceholderObjectOnly { |
| 137 const char kPageDescription[] = "Object, no fallback"; | 130 const char kPageDescription[] = "Object, no fallback"; |
| 138 const std::string page = base::StringPrintf( | 131 const std::string page = base::StringPrintf( |
| 139 "<html><body width='800' height='600'>" | 132 "<html><body width='800' height='600'>" |
| 140 "<p>%s</p>" | 133 "<p>%s</p>" |
| 141 "<object type='application/x-shockwave-flash' data='some.swf'" | 134 "<object type='application/x-shockwave-flash' data='some.swf'" |
| 142 " width='550' height='550'>" | 135 " width='550' height='550'>" |
| 143 "</object>" | 136 "</object>" |
| 144 "</body></html>", | 137 "</body></html>", |
| 145 kPageDescription); | 138 kPageDescription); |
| 146 LoadPage(page); | 139 LoadPage(page); |
| 147 | 140 |
| 148 // Verify that plugin object is replaced with placeholder image. | 141 // Verify that plugin object is replaced with placeholder image. |
| 149 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kPageDescription)] | 142 [ShellEarlGrey waitForWebViewContainingText:kPageDescription]; |
| 150 assertWithMatcher:grey_notNil()]; | |
| 151 [[EarlGrey selectElementWithMatcher:WebViewCssSelector("img[src*='data']")] | 143 [[EarlGrey selectElementWithMatcher:WebViewCssSelector("img[src*='data']")] |
| 152 assertWithMatcher:grey_notNil()]; | 144 assertWithMatcher:grey_notNil()]; |
| 153 } | 145 } |
| 154 | 146 |
| 155 // Tests that a large png <object> is untouched. | 147 // Tests that a large png <object> is untouched. |
| 156 - (void)testPluginPlaceholderPNGObject { | 148 - (void)testPluginPlaceholderPNGObject { |
| 157 const char kPageDescription[] = "PNG object"; | 149 const char kPageDescription[] = "PNG object"; |
| 158 const std::string page = base::StringPrintf( | 150 const std::string page = base::StringPrintf( |
| 159 "<html><body width='800' height='600'>" | 151 "<html><body width='800' height='600'>" |
| 160 "<p>%s</p>" | 152 "<p>%s</p>" |
| 161 "<object data='foo.png' type='image/png' width='550' height='550'>" | 153 "<object data='foo.png' type='image/png' width='550' height='550'>" |
| 162 "</object>" | 154 "</object>" |
| 163 "</body></html>", | 155 "</body></html>", |
| 164 kPageDescription); | 156 kPageDescription); |
| 165 LoadPage(page); | 157 LoadPage(page); |
| 166 | 158 |
| 167 // Verify that placeholder image is not displayed. | 159 // Verify that placeholder image is not displayed. |
| 168 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kPageDescription)] | 160 [ShellEarlGrey waitForWebViewContainingText:kPageDescription]; |
| 169 assertWithMatcher:grey_notNil()]; | |
| 170 [[EarlGrey selectElementWithMatcher:WebViewCssSelector("img")] | 161 [[EarlGrey selectElementWithMatcher:WebViewCssSelector("img")] |
| 171 assertWithMatcher:grey_nil()]; | 162 assertWithMatcher:grey_nil()]; |
| 172 } | 163 } |
| 173 | 164 |
| 174 // Test that non-major plugins (e.g., top/side ads) don't get placeholders. | 165 // Test that non-major plugins (e.g., top/side ads) don't get placeholders. |
| 175 - (void)testPluginPlaceholderSmallFlash { | 166 - (void)testPluginPlaceholderSmallFlash { |
| 176 const char kPageDescription[] = "Flash ads"; | 167 const char kPageDescription[] = "Flash ads"; |
| 177 const std::string page = base::StringPrintf( | 168 const std::string page = base::StringPrintf( |
| 178 "<html><body width='800' height='600'>" | 169 "<html><body width='800' height='600'>" |
| 179 "<p>%s</p>" | 170 "<p>%s</p>" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 196 " codebase='http://download.macromedia.com/pub/shockwave/cabs/'" | 187 " codebase='http://download.macromedia.com/pub/shockwave/cabs/'" |
| 197 "flash/swflash.cab#version=6,0,0,0' width='728' height='90'>" | 188 "flash/swflash.cab#version=6,0,0,0' width='728' height='90'>" |
| 198 " <param name='movie' value='some.swf'>" | 189 " <param name='movie' value='some.swf'>" |
| 199 " <embed src='some.swf' width='728' height='90'>" | 190 " <embed src='some.swf' width='728' height='90'>" |
| 200 "</object>" | 191 "</object>" |
| 201 "</body></html>", | 192 "</body></html>", |
| 202 kPageDescription); | 193 kPageDescription); |
| 203 LoadPage(page); | 194 LoadPage(page); |
| 204 | 195 |
| 205 // Verify that placeholder image is not displayed. | 196 // Verify that placeholder image is not displayed. |
| 206 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kPageDescription)] | 197 [ShellEarlGrey waitForWebViewContainingText:kPageDescription]; |
| 207 assertWithMatcher:grey_notNil()]; | |
| 208 [[EarlGrey selectElementWithMatcher:WebViewCssSelector("img")] | 198 [[EarlGrey selectElementWithMatcher:WebViewCssSelector("img")] |
| 209 assertWithMatcher:grey_nil()]; | 199 assertWithMatcher:grey_nil()]; |
| 210 } | 200 } |
| 211 | 201 |
| 212 @end | 202 @end |
| OLD | NEW |