| 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 <memory> | 5 #include <memory> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" | 9 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" |
| 10 #include "chrome/browser/extensions/api/file_system/file_system_api.h" | 10 #include "chrome/browser/extensions/api/file_system/file_system_api.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 ready_listener.Reply(std::string()); | 69 ready_listener.Reply(std::string()); |
| 70 ASSERT_TRUE(close_listener.WaitUntilSatisfied()); | 70 ASSERT_TRUE(close_listener.WaitUntilSatisfied()); |
| 71 EXPECT_EQ("success", close_listener.message()); | 71 EXPECT_EQ("success", close_listener.message()); |
| 72 } | 72 } |
| 73 | 73 |
| 74 // Tests the declarativeContent API and declarative events. | 74 // Tests the declarativeContent API and declarative events. |
| 75 IN_PROC_BROWSER_TEST_F(NativeBindingsApiTest, DeclarativeEvents) { | 75 IN_PROC_BROWSER_TEST_F(NativeBindingsApiTest, DeclarativeEvents) { |
| 76 host_resolver()->AddRule("*", "127.0.0.1"); | 76 host_resolver()->AddRule("*", "127.0.0.1"); |
| 77 embedded_test_server()->ServeFilesFromDirectory(test_data_dir_); | 77 embedded_test_server()->ServeFilesFromDirectory(test_data_dir_); |
| 78 ASSERT_TRUE(StartEmbeddedTestServer()); | 78 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 79 // Load an extension and wait for it to be ready. | 79 // Load an extension. On load, this extension will a) run a few simple tests |
| 80 // using chrome.test.runTests() and b) set up rules for declarative events for |
| 81 // a browser-driven test. Wait for both the tests to finish and the extension |
| 82 // to be ready. |
| 80 ExtensionTestMessageListener listener("ready", false); | 83 ExtensionTestMessageListener listener("ready", false); |
| 84 ResultCatcher catcher; |
| 81 const Extension* extension = LoadExtension( | 85 const Extension* extension = LoadExtension( |
| 82 test_data_dir_.AppendASCII("native_bindings/declarative_content")); | 86 test_data_dir_.AppendASCII("native_bindings/declarative_content")); |
| 87 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 83 ASSERT_TRUE(extension); | 88 ASSERT_TRUE(extension); |
| 84 ASSERT_TRUE(listener.WaitUntilSatisfied()); | 89 ASSERT_TRUE(listener.WaitUntilSatisfied()); |
| 85 | 90 |
| 86 // The extension's page action should currently be hidden. | 91 // The extension's page action should currently be hidden. |
| 87 ExtensionAction* page_action = | 92 ExtensionAction* page_action = |
| 88 ExtensionActionManager::Get(profile())->GetPageAction(*extension); | 93 ExtensionActionManager::Get(profile())->GetPageAction(*extension); |
| 89 content::WebContents* web_contents = | 94 content::WebContents* web_contents = |
| 90 browser()->tab_strip_model()->GetActiveWebContents(); | 95 browser()->tab_strip_model()->GetActiveWebContents(); |
| 91 int tab_id = SessionTabHelper::IdForTab(web_contents); | 96 int tab_id = SessionTabHelper::IdForTab(web_contents); |
| 92 EXPECT_FALSE(page_action->GetIsVisible(tab_id)); | 97 EXPECT_FALSE(page_action->GetIsVisible(tab_id)); |
| 98 EXPECT_TRUE(page_action->GetDeclarativeIcon(tab_id).IsEmpty()); |
| 93 | 99 |
| 94 // Navigating to example.com should show the page action. | 100 // Navigating to example.com should show the page action. |
| 95 ui_test_utils::NavigateToURL( | 101 ui_test_utils::NavigateToURL( |
| 96 browser(), embedded_test_server()->GetURL( | 102 browser(), embedded_test_server()->GetURL( |
| 97 "example.com", "/native_bindings/simple.html")); | 103 "example.com", "/native_bindings/simple.html")); |
| 98 base::RunLoop().RunUntilIdle(); | 104 base::RunLoop().RunUntilIdle(); |
| 99 EXPECT_TRUE(page_action->GetIsVisible(tab_id)); | 105 EXPECT_TRUE(page_action->GetIsVisible(tab_id)); |
| 106 EXPECT_FALSE(page_action->GetDeclarativeIcon(tab_id).IsEmpty()); |
| 100 | 107 |
| 101 // And the extension should be notified of the click. | 108 // And the extension should be notified of the click. |
| 102 ExtensionTestMessageListener clicked_listener("clicked and removed", false); | 109 ExtensionTestMessageListener clicked_listener("clicked and removed", false); |
| 103 ExtensionActionAPI::Get(profile())->DispatchExtensionActionClicked( | 110 ExtensionActionAPI::Get(profile())->DispatchExtensionActionClicked( |
| 104 *page_action, web_contents); | 111 *page_action, web_contents); |
| 105 ASSERT_TRUE(clicked_listener.WaitUntilSatisfied()); | 112 ASSERT_TRUE(clicked_listener.WaitUntilSatisfied()); |
| 106 } | 113 } |
| 107 | 114 |
| 108 IN_PROC_BROWSER_TEST_F(NativeBindingsApiTest, LazyListeners) { | 115 IN_PROC_BROWSER_TEST_F(NativeBindingsApiTest, LazyListeners) { |
| 109 ProcessManager::SetEventPageIdleTimeForTesting(1); | 116 ProcessManager::SetEventPageIdleTimeForTesting(1); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 ui_test_utils::NavigateToURL( | 246 ui_test_utils::NavigateToURL( |
| 240 browser(), embedded_test_server()->GetURL( | 247 browser(), embedded_test_server()->GetURL( |
| 241 "example.com", "/native_bindings/simple.html")); | 248 "example.com", "/native_bindings/simple.html")); |
| 242 | 249 |
| 243 ExtensionTestMessageListener listener("callback", false); | 250 ExtensionTestMessageListener listener("callback", false); |
| 244 ASSERT_TRUE(LoadExtension(test_dir.UnpackedPath())); | 251 ASSERT_TRUE(LoadExtension(test_dir.UnpackedPath())); |
| 245 EXPECT_TRUE(listener.WaitUntilSatisfied()); | 252 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
| 246 } | 253 } |
| 247 | 254 |
| 248 } // namespace extensions | 255 } // namespace extensions |
| OLD | NEW |