Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 | 6 |
| 7 #if defined(TOOLKIT_GTK) | 7 #if defined(TOOLKIT_GTK) |
| 8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
| 9 #endif | 9 #endif |
| 10 | 10 |
| 11 #include "chrome/browser/chrome_notification_types.h" | 11 #include "chrome/browser/chrome_notification_types.h" |
| 12 #include "chrome/browser/extensions/browser_action_test_util.h" | 12 #include "chrome/browser/extensions/browser_action_test_util.h" |
| 13 #include "chrome/browser/extensions/extension_action.h" | 13 #include "chrome/browser/extensions/extension_action.h" |
| 14 #include "chrome/browser/extensions/extension_action_icon_factory.h" | 14 #include "chrome/browser/extensions/extension_action_icon_factory.h" |
| 15 #include "chrome/browser/extensions/extension_action_manager.h" | 15 #include "chrome/browser/extensions/extension_action_manager.h" |
| 16 #include "chrome/browser/extensions/extension_apitest.h" | 16 #include "chrome/browser/extensions/extension_apitest.h" |
| 17 #include "chrome/browser/extensions/extension_service.h" | 17 #include "chrome/browser/extensions/extension_service.h" |
| 18 #include "chrome/browser/extensions/extension_system.h" | 18 #include "chrome/browser/extensions/extension_system.h" |
| 19 #include "chrome/browser/extensions/extension_tab_util.h" | 19 #include "chrome/browser/extensions/extension_tab_util.h" |
| 20 #include "chrome/browser/extensions/extension_test_message_listener.h" | |
| 20 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/browser/ui/browser.h" | 22 #include "chrome/browser/ui/browser.h" |
| 22 #include "chrome/browser/ui/browser_commands.h" | 23 #include "chrome/browser/ui/browser_commands.h" |
| 23 #include "chrome/browser/ui/browser_window.h" | 24 #include "chrome/browser/ui/browser_window.h" |
| 24 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 25 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 26 #include "chrome/common/extensions/permissions/permissions_data.h" | |
| 25 #include "chrome/common/url_constants.h" | 27 #include "chrome/common/url_constants.h" |
| 26 #include "chrome/test/base/ui_test_utils.h" | 28 #include "chrome/test/base/ui_test_utils.h" |
| 27 #include "content/public/browser/notification_service.h" | 29 #include "content/public/browser/notification_service.h" |
| 28 #include "content/public/browser/web_contents.h" | 30 #include "content/public/browser/web_contents.h" |
| 29 #include "content/public/test/browser_test_utils.h" | 31 #include "content/public/test/browser_test_utils.h" |
| 30 #include "grit/theme_resources.h" | 32 #include "grit/theme_resources.h" |
| 31 #include "ui/base/resource/resource_bundle.h" | 33 #include "ui/base/resource/resource_bundle.h" |
| 32 #include "ui/gfx/rect.h" | 34 #include "ui/gfx/rect.h" |
| 33 #include "ui/gfx/size.h" | 35 #include "ui/gfx/size.h" |
| 34 #include "ui/gfx/image/image_skia.h" | 36 #include "ui/gfx/image/image_skia.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 GetBrowserActionsBar().Press(index); | 85 GetBrowserActionsBar().Press(index); |
| 84 popup_observer.Wait(); | 86 popup_observer.Wait(); |
| 85 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 87 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 86 return GetBrowserActionsBar().HasPopup(); | 88 return GetBrowserActionsBar().HasPopup(); |
| 87 } | 89 } |
| 88 | 90 |
| 89 ExtensionAction* GetBrowserAction(const Extension& extension) { | 91 ExtensionAction* GetBrowserAction(const Extension& extension) { |
| 90 return ExtensionActionManager::Get(browser()->profile())-> | 92 return ExtensionActionManager::Get(browser()->profile())-> |
| 91 GetBrowserAction(extension); | 93 GetBrowserAction(extension); |
| 92 } | 94 } |
| 95 | |
| 96 bool IsGrantedForTab(const Extension* extension, | |
| 97 const content::WebContents* web_contents) { | |
| 98 return PermissionsData::HasAPIPermissionForTab( | |
| 99 extension, | |
| 100 SessionID::IdForTab(web_contents), | |
| 101 APIPermission::kTab); | |
| 102 } | |
| 93 }; | 103 }; |
| 94 | 104 |
| 95 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, Basic) { | 105 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, Basic) { |
| 96 ASSERT_TRUE(test_server()->Start()); | 106 ASSERT_TRUE(test_server()->Start()); |
| 97 ASSERT_TRUE(RunExtensionTest("browser_action/basics")) << message_; | 107 ASSERT_TRUE(RunExtensionTest("browser_action/basics")) << message_; |
| 98 const Extension* extension = GetSingleLoadedExtension(); | 108 const Extension* extension = GetSingleLoadedExtension(); |
| 99 ASSERT_TRUE(extension) << message_; | 109 ASSERT_TRUE(extension) << message_; |
| 100 | 110 |
| 101 // Test that there is a browser action in the toolbar. | 111 // Test that there is a browser action in the toolbar. |
| 102 ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions()); | 112 ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions()); |
| (...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 686 const std::string script = | 696 const std::string script = |
| 687 "window.domAutomationController.send(document.body.style." | 697 "window.domAutomationController.send(document.body.style." |
| 688 "backgroundColor);"; | 698 "backgroundColor);"; |
| 689 std::string result; | 699 std::string result; |
| 690 const std::string frame_xpath; | 700 const std::string frame_xpath; |
| 691 EXPECT_TRUE(content::ExecuteScriptInFrameAndExtractString( | 701 EXPECT_TRUE(content::ExecuteScriptInFrameAndExtractString( |
| 692 tab, frame_xpath, script, &result)); | 702 tab, frame_xpath, script, &result)); |
| 693 EXPECT_EQ(result, "red"); | 703 EXPECT_EQ(result, "red"); |
| 694 } | 704 } |
| 695 | 705 |
| 706 | |
| 707 // http://crbug.com/177163 | |
| 708 #if defined(OS_WIN) && !defined(NDEBUG) | |
| 709 #define MAYBE_TestOpenPopup DISABLED_TestOpenPopup | |
| 710 #else | |
| 711 #define MAYBE_TestOpenPopup TestOpenPopup | |
| 712 #endif | |
| 713 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, MAYBE_TestOpenPopup) { | |
| 714 ExtensionTestMessageListener listener("ready", true); | |
| 715 { | |
| 716 // Show first popup in original window and expect it to have loaded. | |
| 717 content::WindowedNotificationObserver frame_observer( | |
| 718 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | |
| 719 content::NotificationService::AllSources()); | |
| 720 | |
| 721 ASSERT_TRUE(RunExtensionSubtest("browser_action/open_popup", | |
| 722 "open_popup_succeeds.html")) << message_; | |
| 723 frame_observer.Wait(); | |
| 724 EXPECT_TRUE(GetBrowserActionsBar().HasPopup()); | |
| 725 } | |
| 726 | |
| 727 EXPECT_TRUE(listener.WaitUntilSatisfied()); | |
| 728 | |
| 729 { | |
| 730 // Open a new window. | |
| 731 content::WindowedNotificationObserver frame_observer( | |
| 732 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | |
| 733 content::NotificationService::AllSources()); | |
| 734 browser()->OpenURL(content::OpenURLParams( | |
| 735 GURL("about:"), content::Referrer(), NEW_WINDOW, | |
| 736 content::PAGE_TRANSITION_TYPED, false)); | |
| 737 #if defined(OS_WIN) | |
| 738 // Hide all the buttons to test that it opens even when browser action is | |
| 739 // in the overflow bucket. | |
| 740 // TODO(justinlin): Implement for other platforms. | |
| 741 GetBrowserActionsBar().SetIconVisibilityCount(0); | |
| 742 #endif | |
| 743 frame_observer.Wait(); | |
| 744 } | |
| 745 | |
| 746 ResultCatcher catcher; | |
| 747 { | |
| 748 content::WindowedNotificationObserver frame_observer( | |
| 749 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | |
| 750 content::NotificationService::AllSources()); | |
| 751 // Show second popup in new window. | |
| 752 listener.Reply(""); | |
| 753 frame_observer.Wait(); | |
| 754 EXPECT_TRUE(GetBrowserActionsBar().HasPopup()); | |
| 755 } | |
| 756 ASSERT_TRUE(catcher.GetNextResult()) << message_; | |
| 757 } | |
| 758 | |
| 759 // http://crbug.com/177163 | |
| 760 #if defined(OS_WIN) && !defined(NDEBUG) | |
| 761 #define MAYBE_TestOpenPopupIncognito DISABLED_TestOpenPopupIncognito | |
| 762 #else | |
| 763 #define MAYBE_TestOpenPopupIncognito TestOpenPopupIncognito | |
| 764 #endif | |
| 765 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, MAYBE_TestOpenPopupIncognito) { | |
| 766 content::WindowedNotificationObserver frame_observer( | |
| 767 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | |
| 768 content::NotificationService::AllSources()); | |
| 769 ASSERT_TRUE(RunExtensionSubtest("browser_action/open_popup", | |
| 770 "open_popup_succeeds.html", | |
| 771 kFlagEnableIncognito | kFlagUseIncognito)) | |
| 772 << message_; | |
| 773 frame_observer.Wait(); | |
| 774 EXPECT_TRUE(GetBrowserActionsBar().HasPopup()); | |
| 775 } | |
| 776 | |
| 777 // http://crbug.com/177163 | |
| 778 #if defined(OS_WIN) && !defined(NDEBUG) | |
| 779 #define MAYBE_TestOpenPopupIncognitoNotAllowed DISABLED_TestOpenPopupIncognitoNo tAllowed | |
| 780 #else | |
| 781 #define MAYBE_TestOpenPopupIncognitoNotAllowed TestOpenPopupIncognitoNotAllowed | |
| 782 #endif | |
| 783 // Test that the popup does not show in an incognito window if extension is not | |
| 784 // enabled for incognito. | |
|
Finnur
2013/10/17 14:58:34
Line 806 says the popup opened. Is the test incorr
Finnur
2013/10/18 10:31:01
I don't see a reply on this question...
justinlin
2013/10/19 06:01:48
Clarified, sorry missed this and added check that
| |
| 785 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, | |
| 786 MAYBE_TestOpenPopupIncognitoNotAllowed) { | |
| 787 { | |
| 788 // Open an incognito window. | |
| 789 content::WindowedNotificationObserver frame_observer( | |
| 790 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | |
| 791 content::NotificationService::AllSources()); | |
| 792 browser()->OpenURL(content::OpenURLParams( | |
| 793 GURL("about:"), content::Referrer(), OFF_THE_RECORD, | |
| 794 content::PAGE_TRANSITION_TYPED, false)); | |
| 795 frame_observer.Wait(); | |
| 796 } | |
| 797 | |
| 798 { | |
| 799 // Load popup. | |
| 800 content::WindowedNotificationObserver frame_observer( | |
| 801 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | |
| 802 content::NotificationService::AllSources()); | |
| 803 ASSERT_TRUE(RunExtensionSubtest("browser_action/open_popup", | |
| 804 "open_popup_succeeds.html")) << message_; | |
| 805 frame_observer.Wait(); | |
| 806 EXPECT_TRUE(GetBrowserActionsBar().HasPopup()); | |
| 807 } | |
| 808 } | |
| 809 | |
| 810 // http://crbug.com/177163 | |
| 811 #if defined(OS_WIN) && !defined(NDEBUG) | |
| 812 #define MAYBE_TestOpenPopupDoesNotCloseOtherPopups DISABLED_TestOpenPopupDoesNot CloseOtherPopups | |
| 813 #else | |
| 814 #define MAYBE_TestOpenPopupDoesNotCloseOtherPopups TestOpenPopupDoesNotCloseOthe rPopups | |
| 815 #endif | |
| 816 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, | |
| 817 MAYBE_TestOpenPopupDoesNotCloseOtherPopups) { | |
|
Finnur
2013/10/17 14:58:34
I thought the design doc said only the latest popu
justinlin
2013/10/17 18:32:53
Right. Also, this should not overwrite any existin
Finnur
2013/10/18 10:31:01
That's fine. Does the design doc need to be update
justinlin
2013/10/19 06:01:48
I thought it was. Guess not. I think it might have
| |
| 818 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( | |
| 819 "browser_action/popup"))); | |
| 820 | |
| 821 ExtensionTestMessageListener listener("ready", true); | |
| 822 { | |
| 823 // Show first popup in original window and expect it to have loaded. | |
| 824 content::WindowedNotificationObserver frame_observer( | |
| 825 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | |
| 826 content::NotificationService::AllSources()); | |
| 827 | |
| 828 ASSERT_TRUE(RunExtensionSubtest("browser_action/open_popup", | |
| 829 "open_popup_fails.html")) << message_; | |
| 830 frame_observer.Wait(); | |
| 831 } | |
| 832 | |
| 833 EXPECT_TRUE(listener.WaitUntilSatisfied()); | |
| 834 | |
| 835 { | |
| 836 content::WindowedNotificationObserver frame_observer( | |
| 837 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | |
| 838 content::NotificationService::AllSources()); | |
| 839 ASSERT_TRUE(OpenPopup(0)); | |
| 840 frame_observer.Wait(); | |
| 841 EXPECT_TRUE(GetBrowserActionsBar().HasPopup()); | |
|
Finnur
2013/10/17 14:58:34
It is not clear from casual reading of this that t
justinlin
2013/10/17 18:32:53
Done.
| |
| 842 } | |
| 843 | |
| 844 ResultCatcher catcher; | |
| 845 listener.Reply(""); | |
| 846 ASSERT_TRUE(catcher.GetNextResult()) << message_; | |
| 847 } | |
| 848 | |
| 849 // http://crbug.com/177163 | |
| 850 #if defined(OS_WIN) && !defined(NDEBUG) | |
| 851 #define MAYBE_TestOpenPopupDoesNotGrant DISABLED_TestOpenPopupDoesNotGrant | |
| 852 #else | |
| 853 #define MAYBE_TestOpenPopupDoesNotGrant TestOpenPopupDoesNotGrant | |
| 854 #endif | |
| 855 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, MAYBE_TestOpenPopupDoesNotGrant) { | |
| 856 content::WindowedNotificationObserver frame_observer( | |
| 857 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | |
| 858 content::NotificationService::AllSources()); | |
| 859 ASSERT_TRUE(RunExtensionSubtest("browser_action/open_popup", | |
| 860 "open_popup_succeeds.html")) << message_; | |
| 861 frame_observer.Wait(); | |
| 862 | |
| 863 ExtensionService* service = extensions::ExtensionSystem::Get( | |
| 864 browser()->profile())->extension_service(); | |
| 865 ASSERT_FALSE(IsGrantedForTab( | |
| 866 service->GetExtensionById(last_loaded_extension_id_, false), | |
| 867 browser()->tab_strip_model()->GetActiveWebContents())); | |
| 868 } | |
| 869 | |
| 696 } // namespace | 870 } // namespace |
| 697 } // namespace extensions | 871 } // namespace extensions |
| OLD | NEW |