| 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/stringprintf.h" | 6 #include "base/strings/stringprintf.h" |
| 7 #include "chrome/browser/ui/browser.h" | 7 #include "chrome/browser/ui/browser.h" |
| 8 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 8 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 9 #include "chrome/common/chrome_switches.h" | 9 #include "chrome/common/chrome_switches.h" |
| 10 #include "chrome/test/base/in_process_browser_test.h" | 10 #include "chrome/test/base/in_process_browser_test.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 GetActiveWebContents()->GetMainFrame())); | 33 GetActiveWebContents()->GetMainFrame())); |
| 34 } | 34 } |
| 35 | 35 |
| 36 content::WebContents* GetActiveWebContents() { | 36 content::WebContents* GetActiveWebContents() { |
| 37 return browser()->tab_strip_model()->GetActiveWebContents(); | 37 return browser()->tab_strip_model()->GetActiveWebContents(); |
| 38 } | 38 } |
| 39 | 39 |
| 40 bool IsPluginPeripheral(const char* element_id) { | 40 bool IsPluginPeripheral(const char* element_id) { |
| 41 std::string script = base::StringPrintf( | 41 std::string script = base::StringPrintf( |
| 42 "var plugin = window.document.getElementById('%s');" | 42 "var plugin = window.document.getElementById('%s');" |
| 43 "function handleEvent() {" | 43 "function handleEvent(event) {" |
| 44 " if (event.data.isPeripheral != undefined &&" | 44 " if (event.data.isPeripheral != undefined &&" |
| 45 " event.data.source == 'getPeripheralStatusResponse') {" | 45 " event.data.source == 'getPowerSaverStatusResponse') {" |
| 46 " window.domAutomationController.send(" | 46 " window.domAutomationController.send(" |
| 47 " event.data.isPeripheral ? 'peripheral' : 'essential');" | 47 " event.data.isPeripheral ? 'peripheral' : 'essential');" |
| 48 " plugin.removeEventListener('message', handleEvent);" | 48 " plugin.removeEventListener('message', handleEvent);" |
| 49 " }" | 49 " }" |
| 50 "}" | 50 "}" |
| 51 "if (plugin == undefined ||" | 51 "if (plugin == undefined ||" |
| 52 " (plugin.nodeName != 'OBJECT' && plugin.nodeName != 'EMBED')) {" | 52 " (plugin.nodeName != 'OBJECT' && plugin.nodeName != 'EMBED')) {" |
| 53 " window.domAutomationController.send('error');" | 53 " window.domAutomationController.send('error');" |
| 54 "} else if (plugin.postMessage == undefined) {" | 54 "} else if (plugin.postMessage == undefined) {" |
| 55 " window.domAutomationController.send('peripheral');" | 55 " window.domAutomationController.send('peripheral');" |
| 56 "} else {" | 56 "} else {" |
| 57 " plugin.addEventListener('message', handleEvent);" | 57 " plugin.addEventListener('message', handleEvent);" |
| 58 " plugin.postMessage('getPeripheralStatus');" | 58 " plugin.postMessage('getPowerSaverStatus');" |
| 59 "}", | 59 "}", |
| 60 element_id); | 60 element_id); |
| 61 | 61 |
| 62 std::string result; | 62 std::string result; |
| 63 EXPECT_TRUE(content::ExecuteScriptAndExtractString(GetActiveWebContents(), | 63 EXPECT_TRUE(content::ExecuteScriptAndExtractString(GetActiveWebContents(), |
| 64 script, &result)); | 64 script, &result)); |
| 65 EXPECT_NE("error", result); | 65 EXPECT_NE("error", result); |
| 66 return result == "peripheral"; | 66 return result == "peripheral"; |
| 67 } | 67 } |
| 68 | 68 |
| 69 // This sends a simulated click at |point| and waits for test plugin to send | 69 // This sends a simulated click at |point| and waits for test plugin to send |
| 70 // a status message indicating that it is essential. The test plugin sends a | 70 // a status message indicating that it is essential. The test plugin sends a |
| 71 // status message during: | 71 // status message during: |
| 72 // - Plugin creation, to handle a plugin freshly created from a poster. | 72 // - Plugin creation, to handle a plugin freshly created from a poster. |
| 73 // - Peripheral status change. | 73 // - Peripheral status change. |
| 74 // - In response to the explicit 'getPeripheralStatus' request, in case the | 74 // - In response to the explicit 'getPowerSaverStatus' request, in case the |
| 75 // test has missed the above two events. | 75 // test has missed the above two events. |
| 76 void SimulateClickAndAwaitMarkedEssential(const char* element_id, | 76 void SimulateClickAndAwaitMarkedEssential(const char* element_id, |
| 77 const gfx::Point& point) { | 77 const gfx::Point& point) { |
| 78 content::SimulateMouseClickAt(GetActiveWebContents(), 0 /* modifiers */, | 78 content::SimulateMouseClickAt(GetActiveWebContents(), 0 /* modifiers */, |
| 79 blink::WebMouseEvent::ButtonLeft, point); | 79 blink::WebMouseEvent::ButtonLeft, point); |
| 80 | 80 |
| 81 std::string script = base::StringPrintf( | 81 std::string script = base::StringPrintf( |
| 82 "var plugin = window.document.getElementById('%s');" | 82 "var plugin = window.document.getElementById('%s');" |
| 83 "function handleEvent() {" | 83 "function handleEvent(event) {" |
| 84 " if (event.data.isPeripheral == false) {" | 84 " if (event.data.isPeripheral == false) {" |
| 85 " window.domAutomationController.send('essential');" | 85 " window.domAutomationController.send('essential');" |
| 86 " plugin.removeEventListener('message', handleEvent);" | 86 " plugin.removeEventListener('message', handleEvent);" |
| 87 " }" | 87 " }" |
| 88 "}" | 88 "}" |
| 89 "if (plugin == undefined ||" | 89 "if (plugin == undefined ||" |
| 90 " (plugin.nodeName != 'OBJECT' && plugin.nodeName != 'EMBED')) {" | 90 " (plugin.nodeName != 'OBJECT' && plugin.nodeName != 'EMBED')) {" |
| 91 " window.domAutomationController.send('error');" | 91 " window.domAutomationController.send('error');" |
| 92 "} else {" | 92 "} else {" |
| 93 " plugin.addEventListener('message', handleEvent);" | 93 " plugin.addEventListener('message', handleEvent);" |
| 94 " if (plugin.postMessage != undefined) {" | 94 " if (plugin.postMessage != undefined) {" |
| 95 " plugin.postMessage('getPeripheralStatus');" | 95 " plugin.postMessage('getPowerSaverStatus');" |
| 96 " }" | 96 " }" |
| 97 "}", | 97 "}", |
| 98 element_id); | 98 element_id); |
| 99 | 99 |
| 100 std::string result; | 100 std::string result; |
| 101 EXPECT_TRUE(content::ExecuteScriptAndExtractString(GetActiveWebContents(), | 101 EXPECT_TRUE(content::ExecuteScriptAndExtractString(GetActiveWebContents(), |
| 102 script, &result)); | 102 script, &result)); |
| 103 EXPECT_EQ("essential", result); | 103 EXPECT_EQ("essential", result); |
| 104 } | 104 } |
| 105 }; | 105 }; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 } | 174 } |
| 175 | 175 |
| 176 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, LargeCrossOriginObscured) { | 176 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, LargeCrossOriginObscured) { |
| 177 LoadHTML( | 177 LoadHTML( |
| 178 "<div style='width: 100px; height: 100px; overflow: hidden;'>" | 178 "<div style='width: 100px; height: 100px; overflow: hidden;'>" |
| 179 " <object id='plugin' data='http://otherorigin.com/fake.swf' " | 179 " <object id='plugin' data='http://otherorigin.com/fake.swf' " |
| 180 " type='application/x-ppapi-tests' width='400' height='500'></object>" | 180 " type='application/x-ppapi-tests' width='400' height='500'></object>" |
| 181 "</div>"); | 181 "</div>"); |
| 182 EXPECT_TRUE(IsPluginPeripheral("plugin")); | 182 EXPECT_TRUE(IsPluginPeripheral("plugin")); |
| 183 } | 183 } |
| OLD | NEW |