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 // Component App Test 1 of 3: ensure that the initial load of a component | |
| 828 // extension utilising a background page (i.e. a v2 platform app) has its | |
|
Yoyo Zhou
2012/11/27 23:54:18
I think you meant e.g. not i.e.
tapted
2012/11/28 06:21:14
Done.
| |
| 829 // background page run and is launchable. Waits for the Launched response from | |
| 830 // the script resource in the opened shell window. | |
| 831 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, | |
| 832 PRE_PRE_ComponentAppBackgroundPage) { | |
| 833 ExtensionTestMessageListener launched_listener("Launched", false); | |
|
Yoyo Zhou
2012/11/27 23:54:18
Declare this closer to the point where it might st
tapted
2012/11/28 06:21:14
Done.
| |
| 834 content::WindowedNotificationObserver app_loaded_observer( | |
|
Yoyo Zhou
2012/11/27 23:54:18
What is the purpose of this observer? If according
tapted
2012/11/28 06:21:14
I think NOTIFICATION_EXTENSION_INSTALLED comes out
| |
| 835 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | |
| 836 content::NotificationService::AllSources()); | |
| 837 | |
| 838 const Extension* extension = LoadExtensionAsComponent( | |
| 839 test_data_dir_.AppendASCII("platform_apps").AppendASCII("component")); | |
| 840 ASSERT_TRUE(extension); | |
| 841 | |
| 842 app_loaded_observer.Wait(); | |
| 843 | |
| 844 application_launch::OpenApplication(application_launch::LaunchParams( | |
| 845 browser()->profile(), extension, extension_misc::LAUNCH_NONE, | |
| 846 NEW_WINDOW)); | |
| 847 | |
| 848 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | |
| 849 } | |
| 850 | |
| 851 // Component App Test 2 of 3: ensure an installed component app can be launched | |
| 852 // on a subsequent browser start, without requiring any install/upgrade logic | |
| 853 // to be run, then perform setup for step 3. | |
| 854 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, | |
| 855 PRE_ComponentAppBackgroundPage) { | |
| 856 ExtensionTestMessageListener launched_listener("Launched", false); | |
| 857 | |
| 858 // Note: no app_loaded_observer: since component app is now installed, | |
| 859 // re-adding it in the same profile should not cause it to be re-installed. | |
|
Yoyo Zhou
2012/11/27 23:54:18
Is this tested?
tapted
2012/11/28 06:21:14
Initially I had thought checking for an event to _
| |
| 860 const Extension* extension = LoadExtensionAsComponent( | |
| 861 test_data_dir_.AppendASCII("platform_apps").AppendASCII("component")); | |
| 862 ASSERT_TRUE(extension); | |
| 863 | |
| 864 application_launch::OpenApplication(application_launch::LaunchParams( | |
| 865 browser()->profile(), extension, extension_misc::LAUNCH_NONE, | |
| 866 NEW_WINDOW)); | |
| 867 | |
| 868 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | |
| 869 | |
| 870 ExtensionPrefs* extension_prefs = | |
| 871 extensions::ExtensionSystem::Get(browser()->profile())-> | |
| 872 extension_service()->extension_prefs(); | |
| 873 (void)extension_prefs; | |
|
Yoyo Zhou
2012/11/27 23:54:18
What is this for?
tapted
2012/11/28 06:21:14
Ah, sorry - that was a stray from experimenting wi
| |
| 874 | |
| 875 // Clear the registered events to ensure they are updated. | |
|
Yoyo Zhou
2012/11/27 23:54:18
This comment should be at 870.
tapted
2012/11/28 06:21:14
Done.
| |
| 876 extension_prefs->SetRegisteredEvents(extension->id(), | |
| 877 std::set<std::string>()); | |
| 878 | |
| 879 // Simulate a "downgrade" from version 2 in the test manifest.json to 1. | |
| 880 const base::StringValue old_version("1"); | |
| 881 std::string pref_path("extensions.settings."); | |
| 882 pref_path += extension->id(); | |
| 883 pref_path += ".manifest.version"; | |
| 884 extension_prefs->pref_service()->RegisterStringPref( | |
| 885 pref_path.c_str(), std::string(), PrefServiceBase::UNSYNCABLE_PREF); | |
| 886 extension_prefs->pref_service()->Set(pref_path.c_str(), old_version); | |
| 887 } | |
| 888 | |
| 889 // Component App Test 3 of 3: simulate a component extension upgrade that | |
| 890 // re-adds the OnLaunched event, and allows the app to be launched. | |
| 891 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, ComponentAppBackgroundPage) { | |
| 892 ExtensionTestMessageListener launched_listener("Launched", false); | |
| 893 | |
| 894 // Since we are forcing an upgrade, we need to wait for the load again. | |
| 895 content::WindowedNotificationObserver app_loaded_observer( | |
| 896 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | |
| 897 content::NotificationService::AllSources()); | |
| 898 const Extension* extension = LoadExtensionAsComponent( | |
| 899 test_data_dir_.AppendASCII("platform_apps").AppendASCII("component")); | |
| 900 ASSERT_TRUE(extension); | |
| 901 app_loaded_observer.Wait(); | |
| 902 | |
| 903 application_launch::OpenApplication(application_launch::LaunchParams( | |
| 904 browser()->profile(), extension, extension_misc::LAUNCH_NONE, | |
| 905 NEW_WINDOW)); | |
| 906 | |
| 907 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | |
| 908 } | |
| 909 | |
| 826 } // namespace extensions | 910 } // namespace extensions |
| OLD | NEW |