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

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: rebase and move v2 component app added in r169911 (and r170087) into background section in componen… Created 8 years 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 784 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); 818 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
818 ASSERT_TRUE(GetFirstShellWindow()); 819 ASSERT_TRUE(GetFirstShellWindow());
819 820
820 // Now tell the app to reload itself 821 // Now tell the app to reload itself
821 ExtensionTestMessageListener launched_listener2("Launched", false); 822 ExtensionTestMessageListener launched_listener2("Launched", false);
822 launched_listener.Reply("reload"); 823 launched_listener.Reply("reload");
823 ASSERT_TRUE(launched_listener2.WaitUntilSatisfied()); 824 ASSERT_TRUE(launched_listener2.WaitUntilSatisfied());
824 ASSERT_TRUE(GetFirstShellWindow()); 825 ASSERT_TRUE(GetFirstShellWindow());
825 } 826 }
826 827
828 namespace {
829
830 // Simple observer to check for NOTIFICATION_EXTENSION_INSTALLED events to
831 // ensure installation does or does not occur in certain scenarios.
832 class CheckExtensionInstalledObserver : public content::NotificationObserver {
833 public:
834 CheckExtensionInstalledObserver() : seen_(false) {
835 registrar_.Add(this,
836 chrome::NOTIFICATION_EXTENSION_INSTALLED,
837 content::NotificationService::AllSources());
838 }
839
840 bool seen() const {
841 return seen_;
842 };
843
844 // NotificationObserver:
845 virtual void Observe(int type,
846 const content::NotificationSource& source,
847 const content::NotificationDetails& details) OVERRIDE {
848 EXPECT_FALSE(seen_);
849 seen_ = true;
850 }
851
852 private:
853 bool seen_;
854 content::NotificationRegistrar registrar_;
855 };
856
857 } // namespace
858
859 // Component App Test 1 of 3: ensure that the initial load of a component
860 // extension utilizing a background page (e.g. a v2 platform app) has its
861 // background page run and is launchable. Waits for the Launched response from
862 // the script resource in the opened shell window.
863 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
864 PRE_PRE_ComponentAppBackgroundPage) {
865 CheckExtensionInstalledObserver should_install;
866
867 // Ensure that we wait until the background page is run (to register the
868 // OnLaunched listener) before trying to open the application. This is similar
869 // to LoadAndLaunchPlatformApp, but we want to load as a component extension.
870 content::WindowedNotificationObserver app_loaded_observer(
871 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
872 content::NotificationService::AllSources());
873
874 const Extension* extension = LoadExtensionAsComponent(
875 test_data_dir_.AppendASCII("platform_apps").AppendASCII("component"));
876 ASSERT_TRUE(extension);
877
878 app_loaded_observer.Wait();
879 ASSERT_TRUE(should_install.seen());
880
881 ExtensionTestMessageListener launched_listener("Launched", false);
882 application_launch::OpenApplication(application_launch::LaunchParams(
883 browser()->profile(), extension, extension_misc::LAUNCH_NONE,
884 NEW_WINDOW));
885
886 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
887 }
888
889 // Component App Test 2 of 3: ensure an installed component app can be launched
890 // on a subsequent browser start, without requiring any install/upgrade logic
891 // to be run, then perform setup for step 3.
892 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
893 PRE_ComponentAppBackgroundPage) {
894
895 // Since the component app is now installed, re-adding it in the same profile
896 // should not cause it to be re-installed. Instead, we wait for the OnLaunched
897 // in a different observer (which would timeout if not the app was not
898 // previously installed properly) and then check this observer to make sure it
899 // never saw the NOTIFICATION_EXTENSION_INSTALLED event.
900 CheckExtensionInstalledObserver should_not_install;
901 const Extension* extension = LoadExtensionAsComponent(
902 test_data_dir_.AppendASCII("platform_apps").AppendASCII("component"));
903 ASSERT_TRUE(extension);
904
905 ExtensionTestMessageListener launched_listener("Launched", false);
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 ASSERT_FALSE(should_not_install.seen());
912
913 // Simulate a "downgrade" from version 2 in the test manifest.json to 1.
914 ExtensionPrefs* extension_prefs =
915 extensions::ExtensionSystem::Get(browser()->profile())->
916 extension_service()->extension_prefs();
917
918 // Clear the registered events to ensure they are updated.
919 extension_prefs->SetRegisteredEvents(extension->id(),
920 std::set<std::string>());
921
922 const base::StringValue old_version("1");
923 std::string pref_path("extensions.settings.");
924 pref_path += extension->id();
925 pref_path += ".manifest.version";
926 extension_prefs->pref_service()->RegisterStringPref(
927 pref_path.c_str(), std::string(), PrefServiceBase::UNSYNCABLE_PREF);
928 extension_prefs->pref_service()->Set(pref_path.c_str(), old_version);
929 }
930
931 // Component App Test 3 of 3: simulate a component extension upgrade that
932 // re-adds the OnLaunched event, and allows the app to be launched.
933 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, ComponentAppBackgroundPage) {
934 CheckExtensionInstalledObserver should_install;
935 // Since we are forcing an upgrade, we need to wait for the load again.
936 content::WindowedNotificationObserver app_loaded_observer(
937 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
938 content::NotificationService::AllSources());
939
940 const Extension* extension = LoadExtensionAsComponent(
941 test_data_dir_.AppendASCII("platform_apps").AppendASCII("component"));
942 ASSERT_TRUE(extension);
943 app_loaded_observer.Wait();
944 ASSERT_TRUE(should_install.seen());
945
946 ExtensionTestMessageListener launched_listener("Launched", false);
947 application_launch::OpenApplication(application_launch::LaunchParams(
948 browser()->profile(), extension, extension_misc::LAUNCH_NONE,
949 NEW_WINDOW));
950
951 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
952 }
953
827 } // namespace extensions 954 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_url_rewrite_browsertest.cc ('k') | chrome/browser/extensions/test_extension_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698