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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/test/test_timeouts.h" | 6 #include "base/test/test_timeouts.h" |
| 7 #include "base/threading/platform_thread.h" | 7 #include "base/threading/platform_thread.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/app/chrome_command_ids.h" | 9 #include "chrome/app/chrome_command_ids.h" |
| 10 #include "chrome/browser/automation/automation_util.h" | 10 #include "chrome/browser/automation/automation_util.h" |
| 11 #include "chrome/browser/debugger/devtools_window.h" | 11 #include "chrome/browser/debugger/devtools_window.h" |
| 12 #include "chrome/browser/extensions/api/permissions/permissions_api.h" | 12 #include "chrome/browser/extensions/api/permissions/permissions_api.h" |
| 13 #include "chrome/browser/extensions/app_restore_service_factory.h" | 13 #include "chrome/browser/extensions/app_restore_service_factory.h" |
| 14 #include "chrome/browser/extensions/app_restore_service.h" | 14 #include "chrome/browser/extensions/app_restore_service.h" |
| 15 #include "chrome/browser/extensions/extension_browsertest.h" | 15 #include "chrome/browser/extensions/extension_browsertest.h" |
| 16 #include "chrome/browser/extensions/extension_prefs.h" | 16 #include "chrome/browser/extensions/extension_prefs.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_test_message_listener.h" | 19 #include "chrome/browser/extensions/extension_test_message_listener.h" |
| 20 #include "chrome/browser/extensions/platform_app_browsertest_util.h" | 20 #include "chrome/browser/extensions/platform_app_browsertest_util.h" |
| 21 #include "chrome/browser/extensions/platform_app_launcher.h" | 21 #include "chrome/browser/extensions/platform_app_launcher.h" |
| 22 #include "chrome/browser/extensions/shell_window_registry.h" | 22 #include "chrome/browser/extensions/shell_window_registry.h" |
| 23 #include "chrome/browser/prefs/pref_service.h" | |
| 23 #include "chrome/browser/tab_contents/render_view_context_menu.h" | 24 #include "chrome/browser/tab_contents/render_view_context_menu.h" |
| 24 #include "chrome/browser/ui/browser.h" | 25 #include "chrome/browser/ui/browser.h" |
| 25 #include "chrome/browser/ui/browser_tabstrip.h" | 26 #include "chrome/browser/ui/browser_tabstrip.h" |
| 26 #include "chrome/browser/ui/constrained_window_tab_helper.h" | 27 #include "chrome/browser/ui/constrained_window_tab_helper.h" |
| 27 #include "chrome/browser/ui/extensions/application_launch.h" | 28 #include "chrome/browser/ui/extensions/application_launch.h" |
| 28 #include "chrome/browser/ui/extensions/shell_window.h" | 29 #include "chrome/browser/ui/extensions/shell_window.h" |
| 29 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 30 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 30 #include "chrome/common/chrome_notification_types.h" | 31 #include "chrome/common/chrome_notification_types.h" |
| 31 #include "chrome/common/url_constants.h" | 32 #include "chrome/common/url_constants.h" |
| 32 #include "chrome/test/base/ui_test_utils.h" | 33 #include "chrome/test/base/ui_test_utils.h" |
| (...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 816 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | 817 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
| 817 ASSERT_TRUE(GetFirstShellWindow()); | 818 ASSERT_TRUE(GetFirstShellWindow()); |
| 818 | 819 |
| 819 // Now tell the app to reload itself | 820 // Now tell the app to reload itself |
| 820 ExtensionTestMessageListener launched_listener2("Launched", false); | 821 ExtensionTestMessageListener launched_listener2("Launched", false); |
| 821 launched_listener.Reply("reload"); | 822 launched_listener.Reply("reload"); |
| 822 ASSERT_TRUE(launched_listener2.WaitUntilSatisfied()); | 823 ASSERT_TRUE(launched_listener2.WaitUntilSatisfied()); |
| 823 ASSERT_TRUE(GetFirstShellWindow()); | 824 ASSERT_TRUE(GetFirstShellWindow()); |
| 824 } | 825 } |
| 825 | 826 |
| 827 namespace { | |
| 828 | |
| 829 // Simple observer to check for NOTIFICATION_EXTENSION_INSTALLED events to | |
|
tapted
2012/11/28 06:21:14
note: link to new code
| |
| 830 // ensure installation does or does not occur in certain scenarios. | |
| 831 class CheckExtensionInstalledObserver : public content::NotificationObserver { | |
| 832 public: | |
| 833 CheckExtensionInstalledObserver() : seen_(false) { | |
| 834 registrar_.Add(this, | |
| 835 chrome::NOTIFICATION_EXTENSION_INSTALLED, | |
| 836 content::NotificationService::AllSources()); | |
| 837 } | |
| 838 | |
| 839 bool seen() const { | |
| 840 return seen_; | |
| 841 }; | |
| 842 | |
| 843 // NotificationObserver: | |
| 844 virtual void Observe(int type, | |
| 845 const content::NotificationSource& source, | |
| 846 const content::NotificationDetails& details) OVERRIDE { | |
| 847 EXPECT_FALSE(seen_); | |
| 848 seen_ = true; | |
| 849 } | |
| 850 | |
| 851 private: | |
| 852 bool seen_; | |
| 853 content::NotificationRegistrar registrar_; | |
| 854 }; | |
| 855 | |
| 856 } // namespace | |
| 857 | |
| 858 // Component App Test 1 of 3: ensure that the initial load of a component | |
| 859 // extension utilizing a background page (e.g. a v2 platform app) has its | |
| 860 // background page run and is launchable. Waits for the Launched response from | |
| 861 // the script resource in the opened shell window. | |
| 862 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, | |
| 863 PRE_PRE_ComponentAppBackgroundPage) { | |
| 864 CheckExtensionInstalledObserver should_install; | |
| 865 | |
| 866 // Ensure that we wait until the background page is run (to register the | |
| 867 // OnLaunched listener) before trying to open the application. This is similar | |
| 868 // to LoadAndLaunchPlatformApp, but we want to load as a component extension. | |
| 869 content::WindowedNotificationObserver app_loaded_observer( | |
| 870 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | |
| 871 content::NotificationService::AllSources()); | |
| 872 | |
| 873 const Extension* extension = LoadExtensionAsComponent( | |
| 874 test_data_dir_.AppendASCII("platform_apps").AppendASCII("component")); | |
| 875 ASSERT_TRUE(extension); | |
| 876 | |
| 877 app_loaded_observer.Wait(); | |
| 878 ASSERT_TRUE(should_install.seen()); | |
| 879 | |
| 880 ExtensionTestMessageListener launched_listener("Launched", false); | |
| 881 application_launch::OpenApplication(application_launch::LaunchParams( | |
| 882 browser()->profile(), extension, extension_misc::LAUNCH_NONE, | |
| 883 NEW_WINDOW)); | |
| 884 | |
| 885 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | |
| 886 } | |
| 887 | |
| 888 // Component App Test 2 of 3: ensure an installed component app can be launched | |
| 889 // on a subsequent browser start, without requiring any install/upgrade logic | |
| 890 // to be run, then perform setup for step 3. | |
| 891 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, | |
| 892 PRE_ComponentAppBackgroundPage) { | |
| 893 | |
| 894 // Since the component app is now installed, re-adding it in the same profile | |
| 895 // should not cause it to be re-installed. Instead, we wait for the OnLaunched | |
| 896 // in a different observer (which would timeout if not the app was not | |
| 897 // previously installed properly) and then check this observer to make sure it | |
| 898 // never saw the NOTIFICATION_EXTENSION_INSTALLED event. | |
| 899 CheckExtensionInstalledObserver should_not_install; | |
| 900 const Extension* extension = LoadExtensionAsComponent( | |
| 901 test_data_dir_.AppendASCII("platform_apps").AppendASCII("component")); | |
| 902 ASSERT_TRUE(extension); | |
| 903 | |
| 904 ExtensionTestMessageListener launched_listener("Launched", false); | |
| 905 application_launch::OpenApplication(application_launch::LaunchParams( | |
| 906 browser()->profile(), extension, extension_misc::LAUNCH_NONE, | |
| 907 NEW_WINDOW)); | |
| 908 | |
| 909 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | |
| 910 ASSERT_FALSE(should_not_install.seen()); | |
|
tapted
2012/11/28 06:21:14
note: new check to verify re-installation does not
| |
| 911 | |
| 912 // Simulate a "downgrade" from version 2 in the test manifest.json to 1. | |
| 913 ExtensionPrefs* extension_prefs = | |
| 914 extensions::ExtensionSystem::Get(browser()->profile())-> | |
| 915 extension_service()->extension_prefs(); | |
| 916 | |
| 917 // Clear the registered events to ensure they are updated. | |
| 918 extension_prefs->SetRegisteredEvents(extension->id(), | |
| 919 std::set<std::string>()); | |
| 920 | |
| 921 const base::StringValue old_version("1"); | |
| 922 std::string pref_path("extensions.settings."); | |
| 923 pref_path += extension->id(); | |
| 924 pref_path += ".manifest.version"; | |
| 925 extension_prefs->pref_service()->RegisterStringPref( | |
| 926 pref_path.c_str(), std::string(), PrefServiceBase::UNSYNCABLE_PREF); | |
| 927 extension_prefs->pref_service()->Set(pref_path.c_str(), old_version); | |
| 928 } | |
| 929 | |
| 930 // Component App Test 3 of 3: simulate a component extension upgrade that | |
| 931 // re-adds the OnLaunched event, and allows the app to be launched. | |
| 932 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, ComponentAppBackgroundPage) { | |
| 933 CheckExtensionInstalledObserver should_install; | |
| 934 // Since we are forcing an upgrade, we need to wait for the load again. | |
| 935 content::WindowedNotificationObserver app_loaded_observer( | |
| 936 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | |
| 937 content::NotificationService::AllSources()); | |
| 938 | |
| 939 const Extension* extension = LoadExtensionAsComponent( | |
| 940 test_data_dir_.AppendASCII("platform_apps").AppendASCII("component")); | |
| 941 ASSERT_TRUE(extension); | |
| 942 app_loaded_observer.Wait(); | |
| 943 ASSERT_TRUE(should_install.seen()); | |
| 944 | |
| 945 ExtensionTestMessageListener launched_listener("Launched", false); | |
| 946 application_launch::OpenApplication(application_launch::LaunchParams( | |
| 947 browser()->profile(), extension, extension_misc::LAUNCH_NONE, | |
| 948 NEW_WINDOW)); | |
| 949 | |
| 950 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | |
| 951 } | |
| 952 | |
| 826 } // namespace extensions | 953 } // namespace extensions |
| OLD | NEW |