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

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

Issue 1378123003: Adding SSL ETS Tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ets
Patch Set: Rebase. 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 GetBrowserAction(extension); 112 GetBrowserAction(extension);
113 } 113 }
114 114
115 private: 115 private:
116 scoped_ptr<BrowserActionTestUtil> browser_action_test_util_; 116 scoped_ptr<BrowserActionTestUtil> browser_action_test_util_;
117 117
118 DISALLOW_COPY_AND_ASSIGN(BrowserActionApiTest); 118 DISALLOW_COPY_AND_ASSIGN(BrowserActionApiTest);
119 }; 119 };
120 120
121 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, Basic) { 121 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, Basic) {
122 ASSERT_TRUE(test_server()->Start()); 122 ASSERT_TRUE(embedded_test_server()->Start());
123 ASSERT_TRUE(RunExtensionTest("browser_action/basics")) << message_; 123 ASSERT_TRUE(RunExtensionTest("browser_action/basics")) << message_;
124 const Extension* extension = GetSingleLoadedExtension(); 124 const Extension* extension = GetSingleLoadedExtension();
125 ASSERT_TRUE(extension) << message_; 125 ASSERT_TRUE(extension) << message_;
126 126
127 // Test that there is a browser action in the toolbar. 127 // Test that there is a browser action in the toolbar.
128 ASSERT_EQ(1, GetBrowserActionsBar()->NumberOfBrowserActions()); 128 ASSERT_EQ(1, GetBrowserActionsBar()->NumberOfBrowserActions());
129 129
130 // Tell the extension to update the browser action state. 130 // Tell the extension to update the browser action state.
131 ResultCatcher catcher; 131 ResultCatcher catcher;
132 ui_test_utils::NavigateToURL(browser(), 132 ui_test_utils::NavigateToURL(browser(),
133 GURL(extension->GetResourceURL("update.html"))); 133 GURL(extension->GetResourceURL("update.html")));
134 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); 134 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
135 135
136 // Test that we received the changes. 136 // Test that we received the changes.
137 ExtensionAction* action = GetBrowserAction(*extension); 137 ExtensionAction* action = GetBrowserAction(*extension);
138 ASSERT_EQ("Modified", action->GetTitle(ExtensionAction::kDefaultTabId)); 138 ASSERT_EQ("Modified", action->GetTitle(ExtensionAction::kDefaultTabId));
139 ASSERT_EQ("badge", action->GetBadgeText(ExtensionAction::kDefaultTabId)); 139 ASSERT_EQ("badge", action->GetBadgeText(ExtensionAction::kDefaultTabId));
140 ASSERT_EQ(SkColorSetARGB(255, 255, 255, 255), 140 ASSERT_EQ(SkColorSetARGB(255, 255, 255, 255),
141 action->GetBadgeBackgroundColor(ExtensionAction::kDefaultTabId)); 141 action->GetBadgeBackgroundColor(ExtensionAction::kDefaultTabId));
142 142
143 // Simulate the browser action being clicked. 143 // Simulate the browser action being clicked.
144 ui_test_utils::NavigateToURL(browser(), 144 ui_test_utils::NavigateToURL(
145 test_server()->GetURL("files/extensions/test_file.txt")); 145 browser(), embedded_test_server()->GetURL("/extensions/test_file.txt"));
146 146
147 ExtensionActionAPI::Get(browser()->profile())->ExecuteExtensionAction( 147 ExtensionActionAPI::Get(browser()->profile())->ExecuteExtensionAction(
148 extension, browser(), true); 148 extension, browser(), true);
149 149
150 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); 150 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
151 } 151 }
152 152
153 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DynamicBrowserAction) { 153 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DynamicBrowserAction) {
154 ASSERT_TRUE(RunExtensionTest("browser_action/no_icon")) << message_; 154 ASSERT_TRUE(RunExtensionTest("browser_action/no_icon")) << message_;
155 const Extension* extension = GetSingleLoadedExtension(); 155 const Extension* extension = GetSingleLoadedExtension();
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 } 477 }
478 478
479 ASSERT_FALSE(browser_action->HasPopup(tab_id)) 479 ASSERT_FALSE(browser_action->HasPopup(tab_id))
480 << "Browser action popup should have been removed."; 480 << "Browser action popup should have been removed.";
481 ASSERT_TRUE(browser_action->HasPopup(ExtensionAction::kDefaultTabId)) 481 ASSERT_TRUE(browser_action->HasPopup(ExtensionAction::kDefaultTabId))
482 << "Browser action popup default should not be changed by setting " 482 << "Browser action popup default should not be changed by setting "
483 << "a specific tab id."; 483 << "a specific tab id.";
484 } 484 }
485 485
486 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, IncognitoBasic) { 486 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, IncognitoBasic) {
487 ASSERT_TRUE(test_server()->Start()); 487 ASSERT_TRUE(embedded_test_server()->Start());
488 488
489 ASSERT_TRUE(RunExtensionTest("browser_action/basics")) << message_; 489 ASSERT_TRUE(RunExtensionTest("browser_action/basics")) << message_;
490 const Extension* extension = GetSingleLoadedExtension(); 490 const Extension* extension = GetSingleLoadedExtension();
491 ASSERT_TRUE(extension) << message_; 491 ASSERT_TRUE(extension) << message_;
492 492
493 // Test that there is a browser action in the toolbar. 493 // Test that there is a browser action in the toolbar.
494 ASSERT_EQ(1, GetBrowserActionsBar()->NumberOfBrowserActions()); 494 ASSERT_EQ(1, GetBrowserActionsBar()->NumberOfBrowserActions());
495 495
496 // Open an incognito window and test that the browser action isn't there by 496 // Open an incognito window and test that the browser action isn't there by
497 // default. 497 // default.
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 579
580 // It can take a moment for the background page to actually get destroyed 580 // 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 581 // so we wait for the notification before checking that it's really gone
582 // and the badge text has been set. 582 // and the badge text has been set.
583 host_destroyed_observer.Wait(); 583 host_destroyed_observer.Wait();
584 ASSERT_FALSE(manager->GetBackgroundHostForExtension(extension->id())); 584 ASSERT_FALSE(manager->GetBackgroundHostForExtension(extension->id()));
585 ASSERT_EQ("X", action->GetBadgeText(ExtensionAction::kDefaultTabId)); 585 ASSERT_EQ("X", action->GetBadgeText(ExtensionAction::kDefaultTabId));
586 } 586 }
587 587
588 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, BadgeBackgroundColor) { 588 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, BadgeBackgroundColor) {
589 ASSERT_TRUE(test_server()->Start()); 589 ASSERT_TRUE(embedded_test_server()->Start());
590 ASSERT_TRUE(RunExtensionTest("browser_action/color")) << message_; 590 ASSERT_TRUE(RunExtensionTest("browser_action/color")) << message_;
591 const Extension* extension = GetSingleLoadedExtension(); 591 const Extension* extension = GetSingleLoadedExtension();
592 ASSERT_TRUE(extension) << message_; 592 ASSERT_TRUE(extension) << message_;
593 593
594 // Test that there is a browser action in the toolbar. 594 // Test that there is a browser action in the toolbar.
595 ASSERT_EQ(1, GetBrowserActionsBar()->NumberOfBrowserActions()); 595 ASSERT_EQ(1, GetBrowserActionsBar()->NumberOfBrowserActions());
596 596
597 // Test that CSS values (#FF0000) set color correctly. 597 // Test that CSS values (#FF0000) set color correctly.
598 ExtensionAction* action = GetBrowserAction(*extension); 598 ExtensionAction* action = GetBrowserAction(*extension);
599 ASSERT_EQ(SkColorSetARGB(255, 255, 0, 0), 599 ASSERT_EQ(SkColorSetARGB(255, 255, 0, 0),
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 ASSERT_TRUE(catcher.GetNextResult()); 633 ASSERT_TRUE(catcher.GetNextResult());
634 634
635 // Test the getters for a specific tab. 635 // Test the getters for a specific tab.
636 ui_test_utils::NavigateToURL(browser(), 636 ui_test_utils::NavigateToURL(browser(),
637 GURL(extension->GetResourceURL("update2.html"))); 637 GURL(extension->GetResourceURL("update2.html")));
638 ASSERT_TRUE(catcher.GetNextResult()); 638 ASSERT_TRUE(catcher.GetNextResult());
639 } 639 }
640 640
641 // Verify triggering browser action. 641 // Verify triggering browser action.
642 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, TestTriggerBrowserAction) { 642 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, TestTriggerBrowserAction) {
643 ASSERT_TRUE(test_server()->Start()); 643 ASSERT_TRUE(embedded_test_server()->Start());
644 644
645 ASSERT_TRUE(RunExtensionTest("trigger_actions/browser_action")) << message_; 645 ASSERT_TRUE(RunExtensionTest("trigger_actions/browser_action")) << message_;
646 const Extension* extension = GetSingleLoadedExtension(); 646 const Extension* extension = GetSingleLoadedExtension();
647 ASSERT_TRUE(extension) << message_; 647 ASSERT_TRUE(extension) << message_;
648 648
649 // Test that there is a browser action in the toolbar. 649 // Test that there is a browser action in the toolbar.
650 ASSERT_EQ(1, GetBrowserActionsBar()->NumberOfBrowserActions()); 650 ASSERT_EQ(1, GetBrowserActionsBar()->NumberOfBrowserActions());
651 651
652 ui_test_utils::NavigateToURL( 652 ui_test_utils::NavigateToURL(browser(),
653 browser(), 653 embedded_test_server()->GetURL("/simple.html"));
654 test_server()->GetURL("files/simple.html"));
655 654
656 ExtensionAction* browser_action = GetBrowserAction(*extension); 655 ExtensionAction* browser_action = GetBrowserAction(*extension);
657 EXPECT_TRUE(browser_action != NULL); 656 EXPECT_TRUE(browser_action != NULL);
658 657
659 // Simulate a click on the browser action icon. 658 // Simulate a click on the browser action icon.
660 { 659 {
661 ResultCatcher catcher; 660 ResultCatcher catcher;
662 GetBrowserActionsBar()->Press(0); 661 GetBrowserActionsBar()->Press(0);
663 EXPECT_TRUE(catcher.GetNextResult()); 662 EXPECT_TRUE(catcher.GetNextResult());
664 } 663 }
665 664
666 WebContents* tab = 665 WebContents* tab =
667 browser()->tab_strip_model()->GetActiveWebContents(); 666 browser()->tab_strip_model()->GetActiveWebContents();
668 EXPECT_TRUE(tab != NULL); 667 EXPECT_TRUE(tab != NULL);
669 668
670 // Verify that the browser action turned the background color red. 669 // Verify that the browser action turned the background color red.
671 const std::string script = 670 const std::string script =
672 "window.domAutomationController.send(document.body.style." 671 "window.domAutomationController.send(document.body.style."
673 "backgroundColor);"; 672 "backgroundColor);";
674 std::string result; 673 std::string result;
675 EXPECT_TRUE(content::ExecuteScriptAndExtractString(tab, script, &result)); 674 EXPECT_TRUE(content::ExecuteScriptAndExtractString(tab, script, &result));
676 EXPECT_EQ(result, "red"); 675 EXPECT_EQ(result, "red");
677 } 676 }
678 677
679 } // namespace 678 } // namespace
680 } // namespace extensions 679 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698