Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(276)

Side by Side Diff: chrome/browser/extensions/native_bindings_apitest.cc

Issue 2853023002: [Extensions Bindings] Add native declarativeContent verification (Closed)
Patch Set: lazyboy's Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 ExtensionTestMessageListener close_listener(false); 72 ExtensionTestMessageListener close_listener(false);
73 ready_listener.Reply(std::string()); 73 ready_listener.Reply(std::string());
74 ASSERT_TRUE(close_listener.WaitUntilSatisfied()); 74 ASSERT_TRUE(close_listener.WaitUntilSatisfied());
75 EXPECT_EQ("success", close_listener.message()); 75 EXPECT_EQ("success", close_listener.message());
76 } 76 }
77 77
78 // Tests the declarativeContent API and declarative events. 78 // Tests the declarativeContent API and declarative events.
79 IN_PROC_BROWSER_TEST_F(NativeBindingsApiTest, DeclarativeEvents) { 79 IN_PROC_BROWSER_TEST_F(NativeBindingsApiTest, DeclarativeEvents) {
80 embedded_test_server()->ServeFilesFromDirectory(test_data_dir_); 80 embedded_test_server()->ServeFilesFromDirectory(test_data_dir_);
81 ASSERT_TRUE(StartEmbeddedTestServer()); 81 ASSERT_TRUE(StartEmbeddedTestServer());
82 // Load an extension and wait for it to be ready. 82 // Load an extension. On load, this extension will a) run a few simple tests
83 // using chrome.test.runTests() and b) set up rules for declarative events for
84 // a browser-driven test. Wait for both the tests to finish and the extension
85 // to be ready.
83 ExtensionTestMessageListener listener("ready", false); 86 ExtensionTestMessageListener listener("ready", false);
87 ResultCatcher catcher;
84 const Extension* extension = LoadExtension( 88 const Extension* extension = LoadExtension(
85 test_data_dir_.AppendASCII("native_bindings/declarative_content")); 89 test_data_dir_.AppendASCII("native_bindings/declarative_content"));
90 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
86 ASSERT_TRUE(extension); 91 ASSERT_TRUE(extension);
87 ASSERT_TRUE(listener.WaitUntilSatisfied()); 92 ASSERT_TRUE(listener.WaitUntilSatisfied());
88 93
89 // The extension's page action should currently be hidden. 94 // The extension's page action should currently be hidden.
90 ExtensionAction* page_action = 95 ExtensionAction* page_action =
91 ExtensionActionManager::Get(profile())->GetPageAction(*extension); 96 ExtensionActionManager::Get(profile())->GetPageAction(*extension);
92 content::WebContents* web_contents = 97 content::WebContents* web_contents =
93 browser()->tab_strip_model()->GetActiveWebContents(); 98 browser()->tab_strip_model()->GetActiveWebContents();
94 int tab_id = SessionTabHelper::IdForTab(web_contents); 99 int tab_id = SessionTabHelper::IdForTab(web_contents);
95 EXPECT_FALSE(page_action->GetIsVisible(tab_id)); 100 EXPECT_FALSE(page_action->GetIsVisible(tab_id));
101 EXPECT_TRUE(page_action->GetDeclarativeIcon(tab_id).IsEmpty());
96 102
97 // Navigating to example.com should show the page action. 103 // Navigating to example.com should show the page action.
98 ui_test_utils::NavigateToURL( 104 ui_test_utils::NavigateToURL(
99 browser(), embedded_test_server()->GetURL( 105 browser(), embedded_test_server()->GetURL(
100 "example.com", "/native_bindings/simple.html")); 106 "example.com", "/native_bindings/simple.html"));
101 base::RunLoop().RunUntilIdle(); 107 base::RunLoop().RunUntilIdle();
102 EXPECT_TRUE(page_action->GetIsVisible(tab_id)); 108 EXPECT_TRUE(page_action->GetIsVisible(tab_id));
109 EXPECT_FALSE(page_action->GetDeclarativeIcon(tab_id).IsEmpty());
103 110
104 // And the extension should be notified of the click. 111 // And the extension should be notified of the click.
105 ExtensionTestMessageListener clicked_listener("clicked and removed", false); 112 ExtensionTestMessageListener clicked_listener("clicked and removed", false);
106 ExtensionActionAPI::Get(profile())->DispatchExtensionActionClicked( 113 ExtensionActionAPI::Get(profile())->DispatchExtensionActionClicked(
107 *page_action, web_contents); 114 *page_action, web_contents);
108 ASSERT_TRUE(clicked_listener.WaitUntilSatisfied()); 115 ASSERT_TRUE(clicked_listener.WaitUntilSatisfied());
109 } 116 }
110 117
111 IN_PROC_BROWSER_TEST_F(NativeBindingsApiTest, LazyListeners) { 118 IN_PROC_BROWSER_TEST_F(NativeBindingsApiTest, LazyListeners) {
112 ProcessManager::SetEventPageIdleTimeForTesting(1); 119 ProcessManager::SetEventPageIdleTimeForTesting(1);
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 ui_test_utils::NavigateToURL( 247 ui_test_utils::NavigateToURL(
241 browser(), embedded_test_server()->GetURL( 248 browser(), embedded_test_server()->GetURL(
242 "example.com", "/native_bindings/simple.html")); 249 "example.com", "/native_bindings/simple.html"));
243 250
244 ExtensionTestMessageListener listener("callback", false); 251 ExtensionTestMessageListener listener("callback", false);
245 ASSERT_TRUE(LoadExtension(test_dir.UnpackedPath())); 252 ASSERT_TRUE(LoadExtension(test_dir.UnpackedPath()));
246 EXPECT_TRUE(listener.WaitUntilSatisfied()); 253 EXPECT_TRUE(listener.WaitUntilSatisfied());
247 } 254 }
248 255
249 } // namespace extensions 256 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698