Chromium Code Reviews| 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 1b9d46d1afa9908aee306c636d6a0f9ae0c6f096..bc53fcf2c966e3d643e01b308796bae5b06ce5e0 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" |
| @@ -823,4 +824,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 |
|
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.
|
| +// 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); |
|
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.
|
| + 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
|
| + 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. |
|
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 _
|
| + 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; |
|
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
|
| + |
| + // 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.
|
| + 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 |