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

Side by Side Diff: chrome/browser/extensions/platform_app_browsertest.cc

Issue 11275069: Perform install tasks for newly installed or upgraded component apps/extensions. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: various fixes Created 8 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 "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 786 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); 820 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
820 ASSERT_TRUE(GetFirstShellWindow()); 821 ASSERT_TRUE(GetFirstShellWindow());
821 822
822 // Now tell the app to reload itself 823 // Now tell the app to reload itself
823 ExtensionTestMessageListener launched_listener2("Launched", false); 824 ExtensionTestMessageListener launched_listener2("Launched", false);
824 launched_listener.Reply("reload"); 825 launched_listener.Reply("reload");
825 ASSERT_TRUE(launched_listener2.WaitUntilSatisfied()); 826 ASSERT_TRUE(launched_listener2.WaitUntilSatisfied());
826 ASSERT_TRUE(GetFirstShellWindow()); 827 ASSERT_TRUE(GetFirstShellWindow());
827 } 828 }
828 829
830 // Component App Test 1 of 3: ensure that the initial load of a component
831 // extension utilising a background page (i.e. a v2 platform app) has its
832 // background page run and is launchable. Waits for the Launched response from
833 // the script resource in the opened shell window.
834 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
835 PRE_PRE_ComponentAppBackgroundPage) {
836 ExtensionTestMessageListener launched_listener("Launched", false);
837 content::WindowedNotificationObserver app_loaded_observer(
838 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
839 content::NotificationService::AllSources());
840
841 const Extension* extension = LoadExtensionAsComponent(
842 test_data_dir_.AppendASCII("platform_apps").AppendASCII("component"));
843 ASSERT_TRUE(extension);
844
845 app_loaded_observer.Wait();
846
847 application_launch::OpenApplication(application_launch::LaunchParams(
848 browser()->profile(), extension, extension_misc::LAUNCH_NONE,
849 NEW_WINDOW));
850
851 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
852 }
853
854 // Component App Test 2 of 3: ensure an installed component app can be launched
855 // on a subsequent browser start, without requiring any install/upgrade logic
856 // to be run, then perform setup for step 3.
857 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
858 PRE_ComponentAppBackgroundPage) {
859 ExtensionTestMessageListener launched_listener("Launched", false);
860
861 // Note: no app_loaded_observer: since component app is now installed,
862 // re-adding it in the same profile should not cause it to be re-installed.
863 const Extension* extension = LoadExtensionAsComponent(
864 test_data_dir_.AppendASCII("platform_apps").AppendASCII("component"));
865 ASSERT_TRUE(extension);
866
867 application_launch::OpenApplication(application_launch::LaunchParams(
868 browser()->profile(), extension, extension_misc::LAUNCH_NONE,
869 NEW_WINDOW));
870
871 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
872
873 ExtensionPrefs* extension_prefs =
874 extensions::ExtensionSystem::Get(browser()->profile())->
875 extension_service()->extension_prefs();
876 (void)extension_prefs;
877
878 // Clear the registered events to ensure they are updated.
879 extension_prefs->SetRegisteredEvents(extension->id(),
880 std::set<std::string>());
881
882 // Simulate a "downgrade" from version 2 in the test manifest.json to 1.
883 const base::StringValue old_version("1");
884 std::string pref_path("extensions.settings.");
885 pref_path += extension->id();
886 pref_path += ".manifest.version";
887 extension_prefs->pref_service()->RegisterStringPref(
888 pref_path.c_str(), std::string(), PrefServiceBase::UNSYNCABLE_PREF);
889 extension_prefs->pref_service()->Set(pref_path.c_str(), old_version);
890 }
891
892 // Component App Test 3 of 3: simulate a component extension upgrade that
893 // re-adds the OnLaunched event, and allows the app to be launched.
894 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, ComponentAppBackgroundPage) {
895 ExtensionTestMessageListener launched_listener("Launched", false);
896
897 // Since we are forcing an upgrade, we need to wait for the load again.
898 content::WindowedNotificationObserver app_loaded_observer(
899 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
900 content::NotificationService::AllSources());
901 const Extension* extension = LoadExtensionAsComponent(
902 test_data_dir_.AppendASCII("platform_apps").AppendASCII("component"));
903 ASSERT_TRUE(extension);
904 app_loaded_observer.Wait();
905
906 application_launch::OpenApplication(application_launch::LaunchParams(
907 browser()->profile(), extension, extension_misc::LAUNCH_NONE,
908 NEW_WINDOW));
909
910 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
911 }
912
829 } // namespace extensions 913 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698