| 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
|
|
|