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

Side by Side Diff: chrome/browser/extensions/api/extension_action/browser_action_apitest.cc

Issue 1409163006: Migrating tests to use EmbeddedTestServer (/chrome/browser misc) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix rebase bug. Created 5 years, 1 month 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "build/build_config.h" 5 #include "build/build_config.h"
6 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" 6 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h"
7 #include "chrome/browser/extensions/browser_action_test_util.h" 7 #include "chrome/browser/extensions/browser_action_test_util.h"
8 #include "chrome/browser/extensions/extension_action.h" 8 #include "chrome/browser/extensions/extension_action.h"
9 #include "chrome/browser/extensions/extension_action_icon_factory.h" 9 #include "chrome/browser/extensions/extension_action_icon_factory.h"
10 #include "chrome/browser/extensions/extension_action_manager.h" 10 #include "chrome/browser/extensions/extension_action_manager.h"
(...skipping 11 matching lines...) Expand all
22 #include "content/public/browser/web_contents.h" 22 #include "content/public/browser/web_contents.h"
23 #include "content/public/test/browser_test_utils.h" 23 #include "content/public/test/browser_test_utils.h"
24 #include "extensions/browser/extension_registry.h" 24 #include "extensions/browser/extension_registry.h"
25 #include "extensions/browser/extension_system.h" 25 #include "extensions/browser/extension_system.h"
26 #include "extensions/browser/notification_types.h" 26 #include "extensions/browser/notification_types.h"
27 #include "extensions/browser/process_manager.h" 27 #include "extensions/browser/process_manager.h"
28 #include "extensions/browser/test_extension_registry_observer.h" 28 #include "extensions/browser/test_extension_registry_observer.h"
29 #include "extensions/common/feature_switch.h" 29 #include "extensions/common/feature_switch.h"
30 #include "extensions/test/result_catcher.h" 30 #include "extensions/test/result_catcher.h"
31 #include "grit/theme_resources.h" 31 #include "grit/theme_resources.h"
32 #include "net/test/embedded_test_server/embedded_test_server.h"
32 #include "ui/base/resource/resource_bundle.h" 33 #include "ui/base/resource/resource_bundle.h"
33 #include "ui/gfx/geometry/rect.h" 34 #include "ui/gfx/geometry/rect.h"
34 #include "ui/gfx/geometry/size.h" 35 #include "ui/gfx/geometry/size.h"
35 #include "ui/gfx/image/canvas_image_source.h" 36 #include "ui/gfx/image/canvas_image_source.h"
36 #include "ui/gfx/image/image_skia.h" 37 #include "ui/gfx/image/image_skia.h"
37 #include "ui/gfx/image/image_skia_operations.h" 38 #include "ui/gfx/image/image_skia_operations.h"
38 #include "ui/gfx/skia_util.h" 39 #include "ui/gfx/skia_util.h"
39 40
40 using content::WebContents; 41 using content::WebContents;
41 42
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 GetBrowserAction(extension); 113 GetBrowserAction(extension);
113 } 114 }
114 115
115 private: 116 private:
116 scoped_ptr<BrowserActionTestUtil> browser_action_test_util_; 117 scoped_ptr<BrowserActionTestUtil> browser_action_test_util_;
117 118
118 DISALLOW_COPY_AND_ASSIGN(BrowserActionApiTest); 119 DISALLOW_COPY_AND_ASSIGN(BrowserActionApiTest);
119 }; 120 };
120 121
121 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, Basic) { 122 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, Basic) {
122 ASSERT_TRUE(test_server()->Start()); 123 ASSERT_TRUE(embedded_test_server()->Start());
123 ASSERT_TRUE(RunExtensionTest("browser_action/basics")) << message_; 124 ASSERT_TRUE(RunExtensionTest("browser_action/basics")) << message_;
124 const Extension* extension = GetSingleLoadedExtension(); 125 const Extension* extension = GetSingleLoadedExtension();
125 ASSERT_TRUE(extension) << message_; 126 ASSERT_TRUE(extension) << message_;
126 127
127 // Test that there is a browser action in the toolbar. 128 // Test that there is a browser action in the toolbar.
128 ASSERT_EQ(1, GetBrowserActionsBar()->NumberOfBrowserActions()); 129 ASSERT_EQ(1, GetBrowserActionsBar()->NumberOfBrowserActions());
129 130
130 // Tell the extension to update the browser action state. 131 // Tell the extension to update the browser action state.
131 ResultCatcher catcher; 132 ResultCatcher catcher;
132 ui_test_utils::NavigateToURL(browser(), 133 ui_test_utils::NavigateToURL(browser(),
133 GURL(extension->GetResourceURL("update.html"))); 134 GURL(extension->GetResourceURL("update.html")));
134 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); 135 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
135 136
136 // Test that we received the changes. 137 // Test that we received the changes.
137 ExtensionAction* action = GetBrowserAction(*extension); 138 ExtensionAction* action = GetBrowserAction(*extension);
138 ASSERT_EQ("Modified", action->GetTitle(ExtensionAction::kDefaultTabId)); 139 ASSERT_EQ("Modified", action->GetTitle(ExtensionAction::kDefaultTabId));
139 ASSERT_EQ("badge", action->GetBadgeText(ExtensionAction::kDefaultTabId)); 140 ASSERT_EQ("badge", action->GetBadgeText(ExtensionAction::kDefaultTabId));
140 ASSERT_EQ(SkColorSetARGB(255, 255, 255, 255), 141 ASSERT_EQ(SkColorSetARGB(255, 255, 255, 255),
141 action->GetBadgeBackgroundColor(ExtensionAction::kDefaultTabId)); 142 action->GetBadgeBackgroundColor(ExtensionAction::kDefaultTabId));
142 143
143 // Simulate the browser action being clicked. 144 // Simulate the browser action being clicked.
144 ui_test_utils::NavigateToURL(browser(), 145 ui_test_utils::NavigateToURL(
145 test_server()->GetURL("files/extensions/test_file.txt")); 146 browser(), embedded_test_server()->GetURL("/extensions/test_file.txt"));
146 147
147 ExtensionActionAPI::Get(browser()->profile())->ExecuteExtensionAction( 148 ExtensionActionAPI::Get(browser()->profile())->ExecuteExtensionAction(
148 extension, browser(), true); 149 extension, browser(), true);
149 150
150 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); 151 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
151 } 152 }
152 153
153 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DynamicBrowserAction) { 154 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DynamicBrowserAction) {
154 ASSERT_TRUE(RunExtensionTest("browser_action/no_icon")) << message_; 155 ASSERT_TRUE(RunExtensionTest("browser_action/no_icon")) << message_;
155 const Extension* extension = GetSingleLoadedExtension(); 156 const Extension* extension = GetSingleLoadedExtension();
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 } 478 }
478 479
479 ASSERT_FALSE(browser_action->HasPopup(tab_id)) 480 ASSERT_FALSE(browser_action->HasPopup(tab_id))
480 << "Browser action popup should have been removed."; 481 << "Browser action popup should have been removed.";
481 ASSERT_TRUE(browser_action->HasPopup(ExtensionAction::kDefaultTabId)) 482 ASSERT_TRUE(browser_action->HasPopup(ExtensionAction::kDefaultTabId))
482 << "Browser action popup default should not be changed by setting " 483 << "Browser action popup default should not be changed by setting "
483 << "a specific tab id."; 484 << "a specific tab id.";
484 } 485 }
485 486
486 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, IncognitoBasic) { 487 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, IncognitoBasic) {
487 ASSERT_TRUE(test_server()->Start()); 488 ASSERT_TRUE(embedded_test_server()->Start());
488 489
489 ASSERT_TRUE(RunExtensionTest("browser_action/basics")) << message_; 490 ASSERT_TRUE(RunExtensionTest("browser_action/basics")) << message_;
490 const Extension* extension = GetSingleLoadedExtension(); 491 const Extension* extension = GetSingleLoadedExtension();
491 ASSERT_TRUE(extension) << message_; 492 ASSERT_TRUE(extension) << message_;
492 493
493 // Test that there is a browser action in the toolbar. 494 // Test that there is a browser action in the toolbar.
494 ASSERT_EQ(1, GetBrowserActionsBar()->NumberOfBrowserActions()); 495 ASSERT_EQ(1, GetBrowserActionsBar()->NumberOfBrowserActions());
495 496
496 // Open an incognito window and test that the browser action isn't there by 497 // Open an incognito window and test that the browser action isn't there by
497 // default. 498 // default.
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 580
580 // It can take a moment for the background page to actually get destroyed 581 // It can take a moment for the background page to actually get destroyed
581 // so we wait for the notification before checking that it's really gone 582 // so we wait for the notification before checking that it's really gone
582 // and the badge text has been set. 583 // and the badge text has been set.
583 host_destroyed_observer.Wait(); 584 host_destroyed_observer.Wait();
584 ASSERT_FALSE(manager->GetBackgroundHostForExtension(extension->id())); 585 ASSERT_FALSE(manager->GetBackgroundHostForExtension(extension->id()));
585 ASSERT_EQ("X", action->GetBadgeText(ExtensionAction::kDefaultTabId)); 586 ASSERT_EQ("X", action->GetBadgeText(ExtensionAction::kDefaultTabId));
586 } 587 }
587 588
588 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, BadgeBackgroundColor) { 589 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, BadgeBackgroundColor) {
589 ASSERT_TRUE(test_server()->Start()); 590 ASSERT_TRUE(embedded_test_server()->Start());
590 ASSERT_TRUE(RunExtensionTest("browser_action/color")) << message_; 591 ASSERT_TRUE(RunExtensionTest("browser_action/color")) << message_;
591 const Extension* extension = GetSingleLoadedExtension(); 592 const Extension* extension = GetSingleLoadedExtension();
592 ASSERT_TRUE(extension) << message_; 593 ASSERT_TRUE(extension) << message_;
593 594
594 // Test that there is a browser action in the toolbar. 595 // Test that there is a browser action in the toolbar.
595 ASSERT_EQ(1, GetBrowserActionsBar()->NumberOfBrowserActions()); 596 ASSERT_EQ(1, GetBrowserActionsBar()->NumberOfBrowserActions());
596 597
597 // Test that CSS values (#FF0000) set color correctly. 598 // Test that CSS values (#FF0000) set color correctly.
598 ExtensionAction* action = GetBrowserAction(*extension); 599 ExtensionAction* action = GetBrowserAction(*extension);
599 ASSERT_EQ(SkColorSetARGB(255, 255, 0, 0), 600 ASSERT_EQ(SkColorSetARGB(255, 255, 0, 0),
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 ASSERT_TRUE(catcher.GetNextResult()); 642 ASSERT_TRUE(catcher.GetNextResult());
642 643
643 // Test the getters for a specific tab. 644 // Test the getters for a specific tab.
644 ui_test_utils::NavigateToURL(browser(), 645 ui_test_utils::NavigateToURL(browser(),
645 GURL(extension->GetResourceURL("update2.html"))); 646 GURL(extension->GetResourceURL("update2.html")));
646 ASSERT_TRUE(catcher.GetNextResult()); 647 ASSERT_TRUE(catcher.GetNextResult());
647 } 648 }
648 649
649 // Verify triggering browser action. 650 // Verify triggering browser action.
650 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, TestTriggerBrowserAction) { 651 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, TestTriggerBrowserAction) {
651 ASSERT_TRUE(test_server()->Start()); 652 ASSERT_TRUE(embedded_test_server()->Start());
652 653
653 ASSERT_TRUE(RunExtensionTest("trigger_actions/browser_action")) << message_; 654 ASSERT_TRUE(RunExtensionTest("trigger_actions/browser_action")) << message_;
654 const Extension* extension = GetSingleLoadedExtension(); 655 const Extension* extension = GetSingleLoadedExtension();
655 ASSERT_TRUE(extension) << message_; 656 ASSERT_TRUE(extension) << message_;
656 657
657 // Test that there is a browser action in the toolbar. 658 // Test that there is a browser action in the toolbar.
658 ASSERT_EQ(1, GetBrowserActionsBar()->NumberOfBrowserActions()); 659 ASSERT_EQ(1, GetBrowserActionsBar()->NumberOfBrowserActions());
659 660
660 ui_test_utils::NavigateToURL( 661 ui_test_utils::NavigateToURL(browser(),
661 browser(), 662 embedded_test_server()->GetURL("/simple.html"));
662 test_server()->GetURL("files/simple.html"));
663 663
664 ExtensionAction* browser_action = GetBrowserAction(*extension); 664 ExtensionAction* browser_action = GetBrowserAction(*extension);
665 EXPECT_TRUE(browser_action != NULL); 665 EXPECT_TRUE(browser_action != NULL);
666 666
667 // Simulate a click on the browser action icon. 667 // Simulate a click on the browser action icon.
668 { 668 {
669 ResultCatcher catcher; 669 ResultCatcher catcher;
670 GetBrowserActionsBar()->Press(0); 670 GetBrowserActionsBar()->Press(0);
671 EXPECT_TRUE(catcher.GetNextResult()); 671 EXPECT_TRUE(catcher.GetNextResult());
672 } 672 }
673 673
674 WebContents* tab = 674 WebContents* tab =
675 browser()->tab_strip_model()->GetActiveWebContents(); 675 browser()->tab_strip_model()->GetActiveWebContents();
676 EXPECT_TRUE(tab != NULL); 676 EXPECT_TRUE(tab != NULL);
677 677
678 // Verify that the browser action turned the background color red. 678 // Verify that the browser action turned the background color red.
679 const std::string script = 679 const std::string script =
680 "window.domAutomationController.send(document.body.style." 680 "window.domAutomationController.send(document.body.style."
681 "backgroundColor);"; 681 "backgroundColor);";
682 std::string result; 682 std::string result;
683 EXPECT_TRUE(content::ExecuteScriptAndExtractString(tab, script, &result)); 683 EXPECT_TRUE(content::ExecuteScriptAndExtractString(tab, script, &result));
684 EXPECT_EQ(result, "red"); 684 EXPECT_EQ(result, "red");
685 } 685 }
686 686
687 } // namespace 687 } // namespace
688 } // namespace extensions 688 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698