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