Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/strings/string_piece.h" | 6 #include "base/strings/string_piece.h" |
| 7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
| 9 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 9 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 10 #include "chrome/common/chrome_switches.h" | 10 #include "chrome/common/chrome_switches.h" |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 30 "} else {" | 30 "} else {" |
| 31 " %s" | 31 " %s" |
| 32 "}", | 32 "}", |
| 33 element_id.c_str(), test_script.data()); | 33 element_id.c_str(), test_script.data()); |
| 34 std::string result; | 34 std::string result; |
| 35 EXPECT_TRUE( | 35 EXPECT_TRUE( |
| 36 content::ExecuteScriptAndExtractString(contents, script, &result)); | 36 content::ExecuteScriptAndExtractString(contents, script, &result)); |
| 37 return result; | 37 return result; |
| 38 } | 38 } |
| 39 | 39 |
| 40 void VerifyPluginIsPlaceholderOnly(content::WebContents* contents, | 40 // This also tests that we have JavaScript access to the underlying plugin. |
| 41 const char* element_id) { | 41 bool PluginLoaded(content::WebContents* contents, const char* element_id) { |
| 42 std::string result = RunTestScript( | 42 std::string result = RunTestScript( |
| 43 "if (plugin.postMessage === undefined) {" | 43 "if (plugin.postMessage === undefined) {" |
| 44 " window.domAutomationController.send('placeholder');" | 44 " window.domAutomationController.send('poster_only');" |
| 45 "} else {" | 45 "} else {" |
| 46 " window.domAutomationController.send('plugin_loaded');" | 46 " window.domAutomationController.send('plugin_loaded');" |
| 47 "}", | 47 "}", |
| 48 contents, element_id); | 48 contents, element_id); |
| 49 EXPECT_EQ("placeholder", result); | 49 EXPECT_NE("error", result); |
| 50 return result == "plugin_loaded"; | |
| 50 } | 51 } |
| 51 | 52 |
| 52 void VerifyPluginIsPeripheral(content::WebContents* contents, | 53 void VerifyPluginIsThrottled(content::WebContents* contents, |
| 53 const char* element_id) { | 54 const char* element_id) { |
| 54 std::string result = RunTestScript( | 55 std::string result = RunTestScript( |
| 55 "function handleEvent(event) {" | 56 "function handleEvent(event) {" |
| 56 " if (event.data.isPeripheral !== undefined && " | 57 " if (event.data.isPeripheral && event.data.isThrottled && " |
| 57 " event.data.source === 'getPowerSaverStatusResponse') {" | 58 " event.data.isHiddenForPlaceholder) {" |
|
Lei Zhang
2015/05/07 23:15:59
Do you still care about the event's data source?
tommycli
2015/05/08 00:49:00
We don't care about the source anymore. We just ca
| |
| 58 " window.domAutomationController.send(" | 59 " window.domAutomationController.send('throttled');" |
| 59 " event.data.isPeripheral ? 'peripheral' : 'essential');" | |
| 60 " plugin.removeEventListener('message', handleEvent);" | 60 " plugin.removeEventListener('message', handleEvent);" |
| 61 " }" | 61 " }" |
| 62 "}" | 62 "}" |
| 63 "if (plugin.postMessage === undefined) {" | 63 "plugin.addEventListener('message', handleEvent);" |
| 64 " window.domAutomationController.send('peripheral');" | 64 "if (plugin.postMessage !== undefined) {" |
|
Lei Zhang
2015/05/07 23:15:59
So previously, if plugin.postMessage is undefined,
tommycli
2015/05/08 00:49:00
Exactly. Now it expects that if there is no postMe
| |
| 65 "} else {" | |
| 66 " plugin.addEventListener('message', handleEvent);" | |
| 67 " plugin.postMessage('getPowerSaverStatus');" | 65 " plugin.postMessage('getPowerSaverStatus');" |
| 68 "}", | 66 "}", |
| 69 contents, element_id); | 67 contents, element_id); |
| 70 EXPECT_EQ("peripheral", result); | 68 EXPECT_EQ("throttled", result); |
| 69 | |
| 70 // Page should continue to have JavaScript access to all throttled plugins. | |
| 71 EXPECT_TRUE(PluginLoaded(contents, element_id)); | |
| 71 } | 72 } |
| 72 | 73 |
| 73 void VerifyPluginMarkedEssential(content::WebContents* contents, | 74 void VerifyPluginMarkedEssential(content::WebContents* contents, |
| 74 const char* element_id) { | 75 const char* element_id) { |
| 75 std::string result = RunTestScript( | 76 std::string result = RunTestScript( |
| 76 "function handleEvent(event) {" | 77 "function handleEvent(event) {" |
| 77 " if (event.data.isPeripheral === false) {" | 78 " if (event.data.isPeripheral === false) {" |
| 78 " window.domAutomationController.send('essential');" | 79 " window.domAutomationController.send('essential');" |
| 79 " plugin.removeEventListener('message', handleEvent);" | 80 " plugin.removeEventListener('message', handleEvent);" |
| 80 " }" | 81 " }" |
| 81 "}" | 82 "}" |
| 82 "plugin.addEventListener('message', handleEvent);" | 83 "plugin.addEventListener('message', handleEvent);" |
| 83 "if (plugin.postMessage !== undefined) {" | 84 "if (plugin.postMessage !== undefined) {" |
| 84 " plugin.postMessage('getPowerSaverStatus');" | 85 " plugin.postMessage('getPowerSaverStatus');" |
| 85 "}", | 86 "}", |
| 86 contents, element_id); | 87 contents, element_id); |
| 87 EXPECT_EQ("essential", result); | 88 EXPECT_EQ("essential", result); |
| 89 EXPECT_TRUE(PluginLoaded(contents, element_id)); | |
| 88 } | 90 } |
| 89 | 91 |
| 90 } // namespace | 92 } // namespace |
| 91 | 93 |
| 92 class PluginPowerSaverBrowserTest : virtual public InProcessBrowserTest { | 94 class PluginPowerSaverBrowserTest : virtual public InProcessBrowserTest { |
| 93 public: | 95 public: |
| 94 void SetUpCommandLine(base::CommandLine* command_line) override { | 96 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 95 command_line->AppendSwitch(switches::kEnablePluginPowerSaver); | 97 command_line->AppendSwitch(switches::kEnablePluginPowerSaver); |
| 96 command_line->AppendSwitch(switches::kEnablePepperTesting); | 98 command_line->AppendSwitch(switches::kEnablePepperTesting); |
| 97 | 99 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 128 }; | 130 }; |
| 129 | 131 |
| 130 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, SmallSameOrigin) { | 132 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, SmallSameOrigin) { |
| 131 LoadHTML( | 133 LoadHTML( |
| 132 "<object id='plugin' data='fake.swf' " | 134 "<object id='plugin' data='fake.swf' " |
| 133 " type='application/x-ppapi-tests' width='400' height='100'>" | 135 " type='application/x-ppapi-tests' width='400' height='100'>" |
| 134 "</object>"); | 136 "</object>"); |
| 135 VerifyPluginMarkedEssential(GetActiveWebContents(), "plugin"); | 137 VerifyPluginMarkedEssential(GetActiveWebContents(), "plugin"); |
| 136 } | 138 } |
| 137 | 139 |
| 138 // Flaky: https://crbug.com/485160 | 140 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, SmallCrossOrigin) { |
|
tommycli
2015/05/07 17:23:00
I believe this patch incidentally fixes this flaky
Bernhard Bauer
2015/05/07 17:46:28
Does it? I thought there was the race condition wh
tommycli
2015/05/07 17:55:31
Since we changed it to VerifyPluginIsThrottled, it
Bernhard Bauer
2015/05/07 18:23:26
Acknowledged.
Lei Zhang
2015/05/07 23:15:59
Can you add a comment to the top of VerifyPluginIs
tommycli
2015/05/08 00:49:00
Done.
| |
| 139 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, DISABLED_SmallCrossOrigin) { | |
| 140 LoadHTML( | 141 LoadHTML( |
| 141 "<object id='plugin' data='http://otherorigin.com/fake.swf' " | 142 "<object id='plugin' data='http://otherorigin.com/fake.swf' " |
| 142 " type='application/x-ppapi-tests' width='400' height='100'>" | 143 " type='application/x-ppapi-tests' width='400' height='100'>" |
| 143 "</object>"); | 144 "</object>"); |
| 144 VerifyPluginIsPeripheral(GetActiveWebContents(), "plugin"); | 145 VerifyPluginIsThrottled(GetActiveWebContents(), "plugin"); |
| 145 | 146 |
| 146 SimulateClickAndAwaitMarkedEssential("plugin", gfx::Point(50, 50)); | 147 SimulateClickAndAwaitMarkedEssential("plugin", gfx::Point(50, 50)); |
| 147 } | 148 } |
| 148 | 149 |
| 149 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, LargeCrossOrigin) { | 150 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, LargeCrossOrigin) { |
| 150 LoadHTML( | 151 LoadHTML( |
| 151 "<object id='plugin' data='http://otherorigin.com/fake.swf' " | 152 "<object id='plugin' data='http://otherorigin.com/fake.swf' " |
| 152 " type='application/x-ppapi-tests' width='400' height='500'>" | 153 " type='application/x-ppapi-tests' width='400' height='500'>" |
| 153 "</object>"); | 154 "</object>"); |
| 154 VerifyPluginMarkedEssential(GetActiveWebContents(), "plugin"); | 155 VerifyPluginMarkedEssential(GetActiveWebContents(), "plugin"); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 165 "<object id='plugin_legacy_syntax' type='application/x-ppapi-tests' " | 166 "<object id='plugin_legacy_syntax' type='application/x-ppapi-tests' " |
| 166 " width='400' height='500'>" | 167 " width='400' height='500'>" |
| 167 " <param name='poster' value='snapshot1x.png 1x, snapshot2x.png 2x'>" | 168 " <param name='poster' value='snapshot1x.png 1x, snapshot2x.png 2x'>" |
| 168 "</object>" | 169 "</object>" |
| 169 "<embed id='plugin_embed_src' type='application/x-ppapi-tests' " | 170 "<embed id='plugin_embed_src' type='application/x-ppapi-tests' " |
| 170 " width='400' height='500' poster='snapshot1x.png'></embed>" | 171 " width='400' height='500' poster='snapshot1x.png'></embed>" |
| 171 "<embed id='plugin_embed_srcset' type='application/x-ppapi-tests' " | 172 "<embed id='plugin_embed_srcset' type='application/x-ppapi-tests' " |
| 172 " width='400' height='500'" | 173 " width='400' height='500'" |
| 173 " poster='snapshot1x.png 1x, snapshot2x.png 2x'></embed>"); | 174 " poster='snapshot1x.png 1x, snapshot2x.png 2x'></embed>"); |
| 174 | 175 |
| 175 VerifyPluginIsPlaceholderOnly(GetActiveWebContents(), "plugin_src"); | 176 EXPECT_FALSE(PluginLoaded(GetActiveWebContents(), "plugin_src")); |
| 176 VerifyPluginIsPlaceholderOnly(GetActiveWebContents(), "plugin_srcset"); | 177 EXPECT_FALSE(PluginLoaded(GetActiveWebContents(), "plugin_srcset")); |
| 177 VerifyPluginIsPlaceholderOnly(GetActiveWebContents(), "plugin_legacy_syntax"); | 178 EXPECT_FALSE(PluginLoaded(GetActiveWebContents(), "plugin_legacy_syntax")); |
| 178 VerifyPluginIsPlaceholderOnly(GetActiveWebContents(), "plugin_embed_src"); | 179 EXPECT_FALSE(PluginLoaded(GetActiveWebContents(), "plugin_embed_src")); |
| 179 VerifyPluginIsPlaceholderOnly(GetActiveWebContents(), "plugin_embed_srcset"); | 180 EXPECT_FALSE(PluginLoaded(GetActiveWebContents(), "plugin_embed_srcset")); |
| 180 } | 181 } |
| 181 | 182 |
| 182 // flaky: crbug.com/481687 | 183 // flaky: crbug.com/481687 |
| 183 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, | 184 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, |
| 184 DISABLED_PluginMarkedEssentialAfterPosterClicked) { | 185 DISABLED_PluginMarkedEssentialAfterPosterClicked) { |
| 185 LoadHTML( | 186 LoadHTML( |
| 186 "<object id='plugin' type='application/x-ppapi-tests' " | 187 "<object id='plugin' type='application/x-ppapi-tests' " |
| 187 " width='400' height='100' poster='snapshot1x.png'></object>"); | 188 " width='400' height='100' poster='snapshot1x.png'></object>"); |
| 188 VerifyPluginIsPlaceholderOnly(GetActiveWebContents(), "plugin"); | 189 EXPECT_FALSE(PluginLoaded(GetActiveWebContents(), "plugin")); |
| 189 | 190 |
| 190 SimulateClickAndAwaitMarkedEssential("plugin", gfx::Point(50, 50)); | 191 SimulateClickAndAwaitMarkedEssential("plugin", gfx::Point(50, 50)); |
| 191 } | 192 } |
| 192 | 193 |
| 193 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, OriginWhitelisting) { | 194 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, OriginWhitelisting) { |
| 194 LoadHTML( | 195 LoadHTML( |
| 195 "<object id='plugin1' data='http://otherorigin.com/fake1.swf' " | 196 "<object id='plugin1' data='http://otherorigin.com/fake1.swf' " |
| 196 " type='application/x-ppapi-tests' width='400' height='100'></object>" | 197 " type='application/x-ppapi-tests' width='400' height='100'></object>" |
| 197 "<object id='plugin2' data='http://otherorigin.com/fake2.swf' " | 198 "<object id='plugin2' data='http://otherorigin.com/fake2.swf' " |
| 198 " type='application/x-ppapi-tests' width='400' height='500'>" | 199 " type='application/x-ppapi-tests' width='400' height='500'>" |
| 199 "</object>"); | 200 "</object>"); |
| 200 VerifyPluginMarkedEssential(GetActiveWebContents(), "plugin1"); | 201 VerifyPluginMarkedEssential(GetActiveWebContents(), "plugin1"); |
| 201 VerifyPluginMarkedEssential(GetActiveWebContents(), "plugin2"); | 202 VerifyPluginMarkedEssential(GetActiveWebContents(), "plugin2"); |
| 202 } | 203 } |
| 203 | 204 |
| 204 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, LargeCrossOriginObscured) { | 205 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, LargeCrossOriginObscured) { |
| 205 LoadHTML( | 206 LoadHTML( |
| 206 "<div style='width: 100px; height: 100px; overflow: hidden;'>" | 207 "<div style='width: 100px; height: 100px; overflow: hidden;'>" |
| 207 " <object id='plugin' data='http://otherorigin.com/fake.swf' " | 208 " <object id='plugin' data='http://otherorigin.com/fake.swf' " |
| 208 " type='application/x-ppapi-tests' width='400' height='500'>" | 209 " type='application/x-ppapi-tests' width='400' height='500'>" |
| 209 " </object>" | 210 " </object>" |
| 210 "</div>"); | 211 "</div>"); |
| 211 VerifyPluginIsPeripheral(GetActiveWebContents(), "plugin"); | 212 VerifyPluginIsThrottled(GetActiveWebContents(), "plugin"); |
| 212 } | 213 } |
| 213 | 214 |
| 214 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, BackgroundTabPlugins) { | 215 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, BackgroundTabPlugins) { |
| 215 std::string url_str = | 216 std::string url_str = |
| 216 "data:text/html;charset=utf-8," | 217 "data:text/html;charset=utf-8," |
| 217 "<object id='same_origin' type='application/x-ppapi-tests'></object>" | 218 "<object id='same_origin' type='application/x-ppapi-tests'></object>" |
| 218 "<object id='small_cross_origin' data='http://otherorigin.com/fake1.swf' " | 219 "<object id='small_cross_origin' data='http://otherorigin.com/fake1.swf' " |
| 219 " type='application/x-ppapi-tests' width='400' height='100'></object>"; | 220 " type='application/x-ppapi-tests' width='400' height='100'></object>"; |
| 220 ui_test_utils::NavigateToURLWithDisposition( | 221 ui_test_utils::NavigateToURLWithDisposition( |
| 221 browser(), GURL(url_str), NEW_BACKGROUND_TAB, | 222 browser(), GURL(url_str), NEW_BACKGROUND_TAB, |
| 222 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 223 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 223 | 224 |
| 224 ASSERT_EQ(2, browser()->tab_strip_model()->count()); | 225 ASSERT_EQ(2, browser()->tab_strip_model()->count()); |
| 225 content::WebContents* background_contents = | 226 content::WebContents* background_contents = |
| 226 browser()->tab_strip_model()->GetWebContentsAt(1); | 227 browser()->tab_strip_model()->GetWebContentsAt(1); |
| 227 EXPECT_TRUE( | 228 EXPECT_TRUE( |
| 228 content::WaitForRenderFrameReady(background_contents->GetMainFrame())); | 229 content::WaitForRenderFrameReady(background_contents->GetMainFrame())); |
| 229 | 230 |
| 230 VerifyPluginIsPlaceholderOnly(background_contents, "same_origin"); | 231 EXPECT_FALSE(PluginLoaded(background_contents, "same_origin")); |
| 231 VerifyPluginIsPlaceholderOnly(background_contents, "small_cross_origin"); | 232 EXPECT_FALSE(PluginLoaded(background_contents, "small_cross_origin")); |
| 232 | 233 |
| 233 browser()->tab_strip_model()->SelectNextTab(); | 234 browser()->tab_strip_model()->SelectNextTab(); |
| 234 EXPECT_EQ(background_contents, GetActiveWebContents()); | 235 EXPECT_EQ(background_contents, GetActiveWebContents()); |
| 235 | 236 |
| 236 VerifyPluginMarkedEssential(background_contents, "same_origin"); | 237 VerifyPluginMarkedEssential(background_contents, "same_origin"); |
| 237 VerifyPluginIsPeripheral(background_contents, "small_cross_origin"); | 238 VerifyPluginIsThrottled(background_contents, "small_cross_origin"); |
| 238 } | 239 } |
| OLD | NEW |