OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/browser.h" |
| 6 #include "chrome/browser/browser_window.h" |
| 7 #include "chrome/browser/extensions/extension_browsertest.h" |
| 8 #include "chrome/browser/extensions/extensions_service.h" |
| 9 #include "chrome/browser/profile.h" |
| 10 #include "chrome/browser/tab_contents/tab_contents.h" |
| 11 #include "chrome/browser/views/browser_actions_container.h" |
| 12 #include "chrome/browser/views/toolbar_view.h" |
| 13 #include "chrome/common/page_action.h" |
| 14 #include "chrome/test/ui_test_utils.h" |
| 15 |
| 16 static void TestAction(Browser* browser) { |
| 17 // Navigate to a page we have permission to modify. |
| 18 ui_test_utils::NavigateToURL(browser, |
| 19 GURL("http://localhost:1337/files/extensions/test_file.txt")); |
| 20 |
| 21 // Send the command. |
| 22 ExtensionsService* service = browser->profile()->GetExtensionsService(); |
| 23 browser->ExecuteCommand(service->GetBrowserActions()[0]->command_id()); |
| 24 |
| 25 // Verify the command worked. |
| 26 TabContents* tab = browser->GetSelectedTabContents(); |
| 27 bool result = false; |
| 28 ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 29 tab->render_view_host(), L"", |
| 30 L"setInterval(function(){" |
| 31 L" if(document.body.bgColor == 'red'){" |
| 32 L" window.domAutomationController.send(true)}}, 100)", |
| 33 &result); |
| 34 ASSERT_TRUE(result); |
| 35 } |
| 36 |
| 37 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, BrowserAction) { |
| 38 StartHTTPServer(); |
| 39 |
| 40 ASSERT_TRUE(LoadExtension( |
| 41 test_data_dir_.AppendASCII("samples") |
| 42 .AppendASCII("make_page_red"))); |
| 43 |
| 44 // Test that there is a browser action in the toolbar. |
| 45 BrowserActionsContainer* browser_actions = |
| 46 browser()->window()->GetBrowserWindowTesting()->GetToolbarView()-> |
| 47 browser_actions(); |
| 48 ASSERT_EQ(1, browser_actions->num_browser_actions()); |
| 49 |
| 50 TestAction(browser()); |
| 51 } |
| 52 |
| 53 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, BrowserActionNoIcon) { |
| 54 StartHTTPServer(); |
| 55 |
| 56 ASSERT_TRUE(LoadExtension( |
| 57 test_data_dir_.AppendASCII("samples") |
| 58 .AppendASCII("make_page_red_no_icon"))); |
| 59 |
| 60 // Test that there is a *not* a browser action in the toolbar. |
| 61 BrowserActionsContainer* browser_actions = |
| 62 browser()->window()->GetBrowserWindowTesting()->GetToolbarView()-> |
| 63 browser_actions(); |
| 64 ASSERT_EQ(0, browser_actions->num_browser_actions()); |
| 65 |
| 66 TestAction(browser()); |
| 67 } |
OLD | NEW |