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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/platform_app_browsertest.cc
diff --git a/chrome/browser/extensions/platform_app_browsertest.cc b/chrome/browser/extensions/platform_app_browsertest.cc
index da04fa9f134146e2638fc6b5ced568b4dbda4be2..a313805072427d7c341510a9cacce26b41eaf6ff 100644
--- a/chrome/browser/extensions/platform_app_browsertest.cc
+++ b/chrome/browser/extensions/platform_app_browsertest.cc
@@ -20,6 +20,7 @@
#include "chrome/browser/extensions/platform_app_browsertest_util.h"
#include "chrome/browser/extensions/platform_app_launcher.h"
#include "chrome/browser/extensions/shell_window_registry.h"
+#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/tab_contents/render_view_context_menu.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_tabstrip.h"
@@ -826,4 +827,87 @@ IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, ReloadRelaunches) {
ASSERT_TRUE(GetFirstShellWindow());
}
+// Component App Test 1 of 3: ensure that the initial load of a component
+// extension utilising a background page (i.e. a v2 platform app) has its
+// background page run and is launchable. Waits for the Launched response from
+// the script resource in the opened shell window.
+IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
+ PRE_PRE_ComponentAppBackgroundPage) {
+ ExtensionTestMessageListener launched_listener("Launched", false);
+ content::WindowedNotificationObserver app_loaded_observer(
+ content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
+ content::NotificationService::AllSources());
+
+ const Extension* extension = LoadExtensionAsComponent(
+ test_data_dir_.AppendASCII("platform_apps").AppendASCII("component"));
+ ASSERT_TRUE(extension);
+
+ app_loaded_observer.Wait();
+
+ application_launch::OpenApplication(application_launch::LaunchParams(
+ browser()->profile(), extension, extension_misc::LAUNCH_NONE,
+ NEW_WINDOW));
+
+ ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
+}
+
+// Component App Test 2 of 3: ensure an installed component app can be launched
+// on a subsequent browser start, without requiring any install/upgrade logic
+// to be run, then perform setup for step 3.
+IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
+ PRE_ComponentAppBackgroundPage) {
+ ExtensionTestMessageListener launched_listener("Launched", false);
+
+ // Note: no app_loaded_observer: since component app is now installed,
+ // re-adding it in the same profile should not cause it to be re-installed.
+ const Extension* extension = LoadExtensionAsComponent(
+ test_data_dir_.AppendASCII("platform_apps").AppendASCII("component"));
+ ASSERT_TRUE(extension);
+
+ application_launch::OpenApplication(application_launch::LaunchParams(
+ browser()->profile(), extension, extension_misc::LAUNCH_NONE,
+ NEW_WINDOW));
+
+ ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
+
+ ExtensionPrefs* extension_prefs =
+ extensions::ExtensionSystem::Get(browser()->profile())->
+ extension_service()->extension_prefs();
+ (void)extension_prefs;
+
+ // Clear the registered events to ensure they are updated.
+ extension_prefs->SetRegisteredEvents(extension->id(),
+ std::set<std::string>());
+
+ // Simulate a "downgrade" from version 2 in the test manifest.json to 1.
+ const base::StringValue old_version("1");
+ std::string pref_path("extensions.settings.");
+ pref_path += extension->id();
+ pref_path += ".manifest.version";
+ extension_prefs->pref_service()->RegisterStringPref(
+ pref_path.c_str(), std::string(), PrefServiceBase::UNSYNCABLE_PREF);
+ extension_prefs->pref_service()->Set(pref_path.c_str(), old_version);
+}
+
+// Component App Test 3 of 3: simulate a component extension upgrade that
+// re-adds the OnLaunched event, and allows the app to be launched.
+IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, ComponentAppBackgroundPage) {
+ ExtensionTestMessageListener launched_listener("Launched", false);
+
+ // Since we are forcing an upgrade, we need to wait for the load again.
+ content::WindowedNotificationObserver app_loaded_observer(
+ content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
+ content::NotificationService::AllSources());
+ const Extension* extension = LoadExtensionAsComponent(
+ test_data_dir_.AppendASCII("platform_apps").AppendASCII("component"));
+ ASSERT_TRUE(extension);
+ app_loaded_observer.Wait();
+
+ application_launch::OpenApplication(application_launch::LaunchParams(
+ browser()->profile(), extension, extension_misc::LAUNCH_NONE,
+ NEW_WINDOW));
+
+ ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
+}
+
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698