This source file includes following definitions.
- HasCommandWithId
- GetAcceleratorForCommandId
- PlatformInit
- PlatformCancel
- observations_
- Observe
- tabs
- rendered_page_count_
- IsAutoCancelEnabled
- DidGetPreviewPageCount
- DidRenderPreviewPage
- WaitUntilPreviewIsReady
- dialog_size
- CopyTestDataAndSetCommandLineArg
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- RunTestWithDevTools
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- seen
- Observe
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- SetUpCommandLine
- SetUp
- OnAppWindowAdded
- OnAppWindowIconChanged
- OnAppWindowRemoved
- IN_PROC_BROWSER_TEST_F
- mock_user_manager_
- SetUpInProcessBrowserTestFixture
- SetUpOnMainThread
- CleanUpOnMainThread
- TearDownInProcessBrowserTestFixture
- num_request_restart_calls
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
#include "apps/app_window.h"
#include "apps/app_window_registry.h"
#include "apps/common/api/app_runtime.h"
#include "apps/launcher.h"
#include "apps/ui/native_app_window.h"
#include "base/bind.h"
#include "base/command_line.h"
#include "base/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/prefs/pref_service.h"
#include "base/stl_util.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/apps/app_browsertest_util.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/devtools/devtools_window.h"
#include "chrome/browser/extensions/api/permissions/permissions_api.h"
#include "chrome/browser/extensions/component_loader.h"
#include "chrome/browser/extensions/extension_browsertest.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_test_message_listener.h"
#include "chrome/browser/renderer_context_menu/render_view_context_menu.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/extensions/application_launch.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/webui/print_preview/print_preview_ui.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/test_switches.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/user_prefs/pref_registry_syncable.h"
#include "components/web_modal/web_contents_modal_dialog_manager.h"
#include "content/public/browser/devtools_agent_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents_view.h"
#include "content/public/test/test_utils.h"
#include "extensions/browser/event_router.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/pref_names.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "url/gurl.h"
#if defined(OS_CHROMEOS)
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/chromeos/login/mock_user_manager.h"
#include "chrome/browser/chromeos/login/user_manager.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/fake_dbus_thread_manager.h"
#include "chromeos/dbus/fake_power_manager_client.h"
#endif
using apps::AppWindow;
using apps::AppWindowRegistry;
using content::WebContents;
using web_modal::WebContentsModalDialogManager;
namespace app_runtime = apps::api::app_runtime;
namespace extensions {
namespace {
class PlatformAppContextMenu : public RenderViewContextMenu {
public:
PlatformAppContextMenu(content::RenderFrameHost* render_frame_host,
const content::ContextMenuParams& params)
: RenderViewContextMenu(render_frame_host, params) {}
bool HasCommandWithId(int command_id) {
return menu_model_.GetIndexOfCommandId(command_id) != -1;
}
protected:
virtual bool GetAcceleratorForCommandId(
int command_id,
ui::Accelerator* accelerator) OVERRIDE {
return false;
}
virtual void PlatformInit() OVERRIDE {}
virtual void PlatformCancel() OVERRIDE {}
};
class TabsAddedNotificationObserver
: public content::WindowedNotificationObserver {
public:
explicit TabsAddedNotificationObserver(size_t observations)
: content::WindowedNotificationObserver(
chrome::NOTIFICATION_TAB_ADDED,
content::NotificationService::AllSources()),
observations_(observations) {
}
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE {
observed_tabs_.push_back(
content::Details<WebContents>(details).ptr());
if (observed_tabs_.size() == observations_)
content::WindowedNotificationObserver::Observe(type, source, details);
}
const std::vector<content::WebContents*>& tabs() { return observed_tabs_; }
private:
size_t observations_;
std::vector<content::WebContents*> observed_tabs_;
DISALLOW_COPY_AND_ASSIGN(TabsAddedNotificationObserver);
};
class ScopedPreviewTestingDelegate : PrintPreviewUI::TestingDelegate {
public:
explicit ScopedPreviewTestingDelegate(bool auto_cancel)
: auto_cancel_(auto_cancel),
total_page_count_(1),
rendered_page_count_(0) {
PrintPreviewUI::SetDelegateForTesting(this);
}
~ScopedPreviewTestingDelegate() {
PrintPreviewUI::SetDelegateForTesting(NULL);
}
virtual bool IsAutoCancelEnabled() OVERRIDE {
return auto_cancel_;
}
virtual void DidGetPreviewPageCount(int page_count) OVERRIDE {
total_page_count_ = page_count;
}
virtual void DidRenderPreviewPage(const content::WebContents& preview_dialog)
OVERRIDE {
dialog_size_ = preview_dialog.GetView()->GetContainerSize();
++rendered_page_count_;
CHECK(rendered_page_count_ <= total_page_count_);
if (waiting_runner_ && rendered_page_count_ == total_page_count_) {
waiting_runner_->Quit();
}
}
void WaitUntilPreviewIsReady() {
CHECK(!waiting_runner_);
if (rendered_page_count_ < total_page_count_) {
waiting_runner_ = new content::MessageLoopRunner;
waiting_runner_->Run();
waiting_runner_ = NULL;
}
}
gfx::Size dialog_size() {
return dialog_size_;
}
private:
bool auto_cancel_;
int total_page_count_;
int rendered_page_count_;
scoped_refptr<content::MessageLoopRunner> waiting_runner_;
gfx::Size dialog_size_;
};
#if !defined(OS_CHROMEOS) && !defined(OS_WIN)
bool CopyTestDataAndSetCommandLineArg(
const base::FilePath& test_data_file,
const base::FilePath& temp_dir,
const char* filename) {
base::FilePath path = temp_dir.AppendASCII(
filename).NormalizePathSeparators();
if (!(base::CopyFile(test_data_file, path)))
return false;
CommandLine* command_line = CommandLine::ForCurrentProcess();
command_line->AppendArgPath(path);
return true;
}
#endif
#if !defined(OS_CHROMEOS)
const char kTestFilePath[] = "platform_apps/launch_files/test.txt";
#endif
}
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, CreateAndCloseAppWindow) {
const Extension* extension = LoadAndLaunchPlatformApp("minimal");
AppWindow* window = CreateAppWindow(extension);
CloseAppWindow(window);
}
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, OnLaunchedEvent) {
ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch")) << message_;
}
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisabledWindowProperties) {
ASSERT_TRUE(RunPlatformAppTest("platform_apps/disabled_window_properties"))
<< message_;
}
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, EmptyContextMenu) {
ExtensionTestMessageListener launched_listener("Launched", false);
LoadAndLaunchPlatformApp("minimal");
ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
WebContents* web_contents = GetFirstAppWindowWebContents();
ASSERT_TRUE(web_contents);
content::ContextMenuParams params;
scoped_ptr<PlatformAppContextMenu> menu;
menu.reset(new PlatformAppContextMenu(web_contents->GetMainFrame(), params));
menu->Init();
ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT));
ASSERT_TRUE(
menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE));
ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP));
ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK));
ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE));
}
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenu) {
ExtensionTestMessageListener launched_listener("Launched", false);
LoadAndLaunchPlatformApp("context_menu");
ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
WebContents* web_contents = GetFirstAppWindowWebContents();
ASSERT_TRUE(web_contents);
content::ContextMenuParams params;
scoped_ptr<PlatformAppContextMenu> menu;
menu.reset(new PlatformAppContextMenu(web_contents->GetMainFrame(), params));
menu->Init();
ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST));
ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + 1));
ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT));
ASSERT_TRUE(
menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE));
ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP));
ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK));
ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE));
ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO));
}
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, InstalledAppWithContextMenu) {
ExtensionTestMessageListener launched_listener("Launched", false);
InstallAndLaunchPlatformApp("context_menu");
ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
WebContents* web_contents = GetFirstAppWindowWebContents();
ASSERT_TRUE(web_contents);
content::ContextMenuParams params;
scoped_ptr<PlatformAppContextMenu> menu;
menu.reset(new PlatformAppContextMenu(web_contents->GetMainFrame(), params));
menu->Init();
ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST));
ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + 1));
ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT));
ASSERT_FALSE(
menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE));
ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP));
ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK));
ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE));
ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO));
}
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuTextField) {
ExtensionTestMessageListener launched_listener("Launched", false);
LoadAndLaunchPlatformApp("context_menu");
ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
WebContents* web_contents = GetFirstAppWindowWebContents();
ASSERT_TRUE(web_contents);
content::ContextMenuParams params;
params.is_editable = true;
scoped_ptr<PlatformAppContextMenu> menu;
menu.reset(new PlatformAppContextMenu(web_contents->GetMainFrame(), params));
menu->Init();
ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST));
ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT));
ASSERT_TRUE(
menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE));
ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP));
ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO));
ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_COPY));
ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK));
ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE));
}
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuSelection) {
ExtensionTestMessageListener launched_listener("Launched", false);
LoadAndLaunchPlatformApp("context_menu");
ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
WebContents* web_contents = GetFirstAppWindowWebContents();
ASSERT_TRUE(web_contents);
content::ContextMenuParams params;
params.selection_text = base::ASCIIToUTF16("Hello World");
scoped_ptr<PlatformAppContextMenu> menu;
menu.reset(new PlatformAppContextMenu(web_contents->GetMainFrame(), params));
menu->Init();
ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST));
ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT));
ASSERT_TRUE(
menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE));
ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP));
ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO));
ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_COPY));
ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK));
ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE));
}
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuClicked) {
ExtensionTestMessageListener launched_listener("Launched", false);
LoadAndLaunchPlatformApp("context_menu_click");
ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
WebContents* web_contents = GetFirstAppWindowWebContents();
ASSERT_TRUE(web_contents);
content::ContextMenuParams params;
params.page_url = GURL("http://foo.bar");
scoped_ptr<PlatformAppContextMenu> menu;
menu.reset(new PlatformAppContextMenu(web_contents->GetMainFrame(), params));
menu->Init();
ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST));
ExtensionTestMessageListener onclicked_listener("onClicked fired for id1",
false);
menu->ExecuteCommand(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST, 0);
ASSERT_TRUE(onclicked_listener.WaitUntilSatisfied());
}
#if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA)
#define MAYBE_DisallowNavigation DISABLED_DisallowNavigation
#else
#define MAYBE_DisallowNavigation DisallowNavigation
#endif
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, MAYBE_DisallowNavigation) {
TabsAddedNotificationObserver observer(2);
ASSERT_TRUE(StartEmbeddedTestServer());
ASSERT_TRUE(RunPlatformAppTest("platform_apps/navigation")) << message_;
observer.Wait();
ASSERT_EQ(2U, observer.tabs().size());
EXPECT_EQ(std::string(chrome::kExtensionInvalidRequestURL),
observer.tabs()[0]->GetURL().spec());
EXPECT_EQ("http://chromium.org/",
observer.tabs()[1]->GetURL().spec());
}
#if (defined(OS_WIN) || defined(OS_LINUX)) && defined(ARCH_CPU_X86)
#define MAYBE_Iframes DISABLED_Iframes
#else
#define MAYBE_Iframes Iframes
#endif
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, MAYBE_Iframes) {
ASSERT_TRUE(StartEmbeddedTestServer());
ASSERT_TRUE(RunPlatformAppTest("platform_apps/iframes")) << message_;
}
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisallowStorage) {
ASSERT_TRUE(RunPlatformAppTest("platform_apps/storage")) << message_;
}
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, Restrictions) {
ASSERT_TRUE(RunPlatformAppTest("platform_apps/restrictions")) << message_;
}
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, PlatformAppsOnly) {
ASSERT_TRUE(RunExtensionTestIgnoreManifestWarnings(
"platform_apps/apps_only")) << message_;
}
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, Isolation) {
ASSERT_TRUE(StartEmbeddedTestServer());
GURL set_cookie_url = embedded_test_server()->GetURL(
"/extensions/platform_apps/isolation/set_cookie.html");
GURL::Replacements replace_host;
std::string host_str("localhost");
replace_host.SetHostStr(host_str);
set_cookie_url = set_cookie_url.ReplaceComponents(replace_host);
ui_test_utils::NavigateToURLWithDisposition(
browser(), set_cookie_url,
CURRENT_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
int cookie_size;
std::string cookie_value;
ui_test_utils::GetCookies(
set_cookie_url,
browser()->tab_strip_model()->GetWebContentsAt(0),
&cookie_size,
&cookie_value);
ASSERT_EQ("testCookie=1", cookie_value);
ASSERT_TRUE(RunPlatformAppTest("platform_apps/isolation")) << message_;
}
#if defined(OS_WIN)
#define MAYBE_ExtensionWindowingApis DISABLED_ExtensionWindowingApis
#else
#define MAYBE_ExtensionWindowingApis ExtensionWindowingApis
#endif
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, MAYBE_ExtensionWindowingApis) {
const Extension* extension = LoadExtension(
test_data_dir_.AppendASCII("common/background_page"));
ASSERT_EQ(1U, RunGetWindowsFunctionForExtension(extension));
ASSERT_EQ(0U, GetAppWindowCount());
ExtensionTestMessageListener launched_listener("Launched", false);
LoadAndLaunchPlatformApp("minimal");
ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
ASSERT_EQ(1U, GetAppWindowCount());
int app_window_id = GetFirstAppWindow()->session_id().id();
ASSERT_EQ(1U, RunGetWindowsFunctionForExtension(extension));
ASSERT_FALSE(RunGetWindowFunctionForExtension(app_window_id, extension));
ExtensionTestMessageListener launched_listener2("Launched", false);
LoadAndLaunchPlatformApp("context_menu");
ASSERT_TRUE(launched_listener2.WaitUntilSatisfied());
ASSERT_EQ(2U, GetAppWindowCount());
}
#if !defined(OS_CHROMEOS)
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithFile) {
SetCommandLineArg(kTestFilePath);
ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_file"))
<< message_;
}
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithRelativeFile) {
ClearCommandLineArgs();
CommandLine* command_line = CommandLine::ForCurrentProcess();
base::FilePath relative_test_doc =
base::FilePath::FromUTF8Unsafe(kTestFilePath);
relative_test_doc = relative_test_doc.NormalizePathSeparators();
command_line->AppendArgPath(relative_test_doc);
ResultCatcher catcher;
const Extension* extension = LoadExtension(
test_data_dir_.AppendASCII("platform_apps/launch_file"));
ASSERT_TRUE(extension);
AppLaunchParams params(
browser()->profile(), extension, LAUNCH_CONTAINER_NONE, NEW_WINDOW);
params.command_line = *CommandLine::ForCurrentProcess();
params.current_directory = test_data_dir_;
OpenApplication(params);
if (!catcher.GetNextResult()) {
message_ = catcher.message();
ASSERT_TRUE(0);
}
}
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithFileExtension) {
SetCommandLineArg(kTestFilePath);
ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_file_by_extension"))
<< message_;
}
#if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA)
#define MAYBE_LaunchWithFileExtensionAndMimeType DISABLED_LaunchWithFileExtensionAndMimeType
#else
#define MAYBE_LaunchWithFileExtensionAndMimeType LaunchWithFileExtensionAndMimeType
#endif
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
MAYBE_LaunchWithFileExtensionAndMimeType) {
SetCommandLineArg(kTestFilePath);
ASSERT_TRUE(RunPlatformAppTest(
"platform_apps/launch_file_by_extension_and_type")) << message_;
}
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithFileWithoutExtension) {
SetCommandLineArg("platform_apps/launch_files/test");
ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_file_with_no_extension"))
<< message_;
}
#if !defined(OS_WIN)
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithFileEmptyExtension) {
base::ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
ClearCommandLineArgs();
ASSERT_TRUE(CopyTestDataAndSetCommandLineArg(
test_data_dir_.AppendASCII(kTestFilePath),
temp_dir.path(),
"test."));
ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_file_with_no_extension"))
<< message_;
}
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
LaunchWithFileEmptyExtensionAcceptAny) {
base::ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
ClearCommandLineArgs();
ASSERT_TRUE(CopyTestDataAndSetCommandLineArg(
test_data_dir_.AppendASCII(kTestFilePath),
temp_dir.path(),
"test."));
ASSERT_TRUE(RunPlatformAppTest(
"platform_apps/launch_file_with_any_extension")) << message_;
}
#endif
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
LaunchWithFileWithoutExtensionAcceptAny) {
SetCommandLineArg("platform_apps/launch_files/test");
ASSERT_TRUE(RunPlatformAppTest(
"platform_apps/launch_file_with_any_extension")) << message_;
}
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
LaunchWithFileAcceptAnyExtension) {
SetCommandLineArg(kTestFilePath);
ASSERT_TRUE(RunPlatformAppTest(
"platform_apps/launch_file_with_any_extension")) << message_;
}
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithWrongExtension) {
SetCommandLineArg(kTestFilePath);
ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_wrong_extension"))
<< message_;
}
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithWrongEmptyExtension) {
SetCommandLineArg("platform_apps/launch_files/test");
ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_wrong_extension"))
<< message_;
}
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithWrongType) {
SetCommandLineArg(kTestFilePath);
ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_wrong_type"))
<< message_;
}
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithNoIntent) {
SetCommandLineArg(kTestFilePath);
ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_no_intent"))
<< message_;
}
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchNoType) {
SetCommandLineArg("platform_apps/launch_files/test.unknownextension");
ASSERT_TRUE(RunPlatformAppTest(
"platform_apps/launch_application_octet_stream")) << message_;
}
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchNoFile) {
SetCommandLineArg("platform_apps/launch_files/doesnotexist.txt");
ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_invalid"))
<< message_;
}
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithDirectory) {
SetCommandLineArg("platform_apps/launch_files");
ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_invalid"))
<< message_;
}
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithNothing) {
ClearCommandLineArgs();
ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_nothing"))
<< message_;
}
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, GetDisplayPath) {
SetCommandLineArg(kTestFilePath);
ASSERT_TRUE(RunPlatformAppTest("platform_apps/get_display_path"))
<< message_;
}
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchNewFile) {
base::ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
ClearCommandLineArgs();
CommandLine* command_line = CommandLine::ForCurrentProcess();
command_line->AppendArgPath(temp_dir.path().AppendASCII("new_file.txt"));
ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_new_file")) << message_;
}
#endif
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, OpenLink) {
ASSERT_TRUE(StartEmbeddedTestServer());
content::WindowedNotificationObserver observer(
chrome::NOTIFICATION_TAB_ADDED,
content::Source<content::WebContentsDelegate>(browser()));
LoadAndLaunchPlatformApp("open_link");
observer.Wait();
ASSERT_EQ(2, browser()->tab_strip_model()->count());
}
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, MutationEventsDisabled) {
ASSERT_TRUE(RunPlatformAppTest("platform_apps/mutation_events")) << message_;
}
#if defined(OS_LINUX) && !defined(USE_ASH)
#define MAYBE_AppWindowRestoreState DISABLED_AppWindowRestoreState
#else
#define MAYBE_AppWindowRestoreState AppWindowRestoreState
#endif
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, MAYBE_AppWindowRestoreState) {
ASSERT_TRUE(RunPlatformAppTest("platform_apps/restore_state"));
}
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
AppWindowAdjustBoundsToBeVisibleOnScreen) {
const Extension* extension = LoadAndLaunchPlatformApp("minimal");
AppWindow* window = CreateAppWindow(extension);
gfx::Rect cached_bounds(80, 100, 400, 400);
gfx::Rect cached_screen_bounds(0, 0, 1600, 900);
gfx::Rect current_screen_bounds(0, 0, 1600, 900);
gfx::Size minimum_size(200, 200);
gfx::Rect bounds;
CallAdjustBoundsToBeVisibleOnScreenForAppWindow(window,
cached_bounds,
cached_screen_bounds,
current_screen_bounds,
minimum_size,
&bounds);
EXPECT_EQ(bounds, cached_bounds);
gfx::Rect empty_screen_bounds;
CallAdjustBoundsToBeVisibleOnScreenForAppWindow(window,
cached_bounds,
empty_screen_bounds,
current_screen_bounds,
minimum_size,
&bounds);
EXPECT_EQ(bounds, cached_bounds);
gfx::Rect horizontal_out_of_screen_bounds(-800, 100, 400, 400);
CallAdjustBoundsToBeVisibleOnScreenForAppWindow(
window,
horizontal_out_of_screen_bounds,
gfx::Rect(-1366, 0, 1600, 900),
current_screen_bounds,
minimum_size,
&bounds);
EXPECT_EQ(bounds, gfx::Rect(0, 100, 400, 400));
gfx::Rect vertical_out_of_screen_bounds(10, 1000, 400, 400);
CallAdjustBoundsToBeVisibleOnScreenForAppWindow(
window,
vertical_out_of_screen_bounds,
gfx::Rect(-1366, 0, 1600, 900),
current_screen_bounds,
minimum_size,
&bounds);
EXPECT_EQ(bounds, gfx::Rect(10, 500, 400, 400));
gfx::Rect big_cache_bounds(10, 10, 1000, 1000);
CallAdjustBoundsToBeVisibleOnScreenForAppWindow(window,
big_cache_bounds,
gfx::Rect(0, 0, 1600, 1000),
gfx::Rect(0, 0, 800, 600),
minimum_size,
&bounds);
EXPECT_EQ(bounds, gfx::Rect(0, 0, 800, 600));
CallAdjustBoundsToBeVisibleOnScreenForAppWindow(window,
big_cache_bounds,
gfx::Rect(0, 0, 1600, 1000),
gfx::Rect(0, 0, 800, 600),
gfx::Size(900, 900),
&bounds);
EXPECT_EQ(bounds, gfx::Rect(0, 0, 900, 900));
}
namespace {
class PlatformAppDevToolsBrowserTest : public PlatformAppBrowserTest {
protected:
enum TestFlags {
RELAUNCH = 0x1,
HAS_ID = 0x2,
};
void RunTestWithDevTools(const char* name, int test_flags);
};
void PlatformAppDevToolsBrowserTest::RunTestWithDevTools(
const char* name, int test_flags) {
using content::DevToolsAgentHost;
ExtensionTestMessageListener launched_listener("Launched", false);
const Extension* extension = LoadAndLaunchPlatformApp(name);
ASSERT_TRUE(extension);
ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
AppWindow* window = GetFirstAppWindow();
ASSERT_TRUE(window);
ASSERT_EQ(window->window_key().empty(), (test_flags & HAS_ID) == 0);
content::RenderViewHost* rvh = window->web_contents()->GetRenderViewHost();
ASSERT_TRUE(rvh);
ASSERT_FALSE(DevToolsAgentHost::HasFor(rvh));
DevToolsWindow::OpenDevToolsWindow(rvh);
ASSERT_TRUE(DevToolsAgentHost::HasFor(rvh));
if (test_flags & RELAUNCH) {
CloseAppWindow(window);
ASSERT_FALSE(GetFirstAppWindow());
content::WindowedNotificationObserver app_loaded_observer(
content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
content::NotificationService::AllSources());
OpenApplication(AppLaunchParams(
browser()->profile(), extension, LAUNCH_CONTAINER_NONE, NEW_WINDOW));
app_loaded_observer.Wait();
window = GetFirstAppWindow();
ASSERT_TRUE(window);
rvh = window->web_contents()->GetRenderViewHost();
ASSERT_TRUE(rvh);
ASSERT_TRUE(DevToolsAgentHost::HasFor(rvh));
}
}
}
#if defined(OS_CHROMEOS)
#define MAYBE_ReOpenedWithID DISABLED_ReOpenedWithID
#else
#define MAYBE_ReOpenedWithID ReOpenedWithID
#endif
IN_PROC_BROWSER_TEST_F(PlatformAppDevToolsBrowserTest, MAYBE_ReOpenedWithID) {
#if defined(OS_WIN) && defined(USE_ASH)
if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests))
return;
#endif
RunTestWithDevTools("minimal_id", RELAUNCH | HAS_ID);
}
#if defined(OS_CHROMEOS) || defined(OS_WIN)
#define MAYBE_ReOpenedWithURL DISABLED_ReOpenedWithURL
#else
#define MAYBE_ReOpenedWithURL ReOpenedWithURL
#endif
IN_PROC_BROWSER_TEST_F(PlatformAppDevToolsBrowserTest, MAYBE_ReOpenedWithURL) {
RunTestWithDevTools("minimal", RELAUNCH);
}
#if defined(OS_MACOSX)
#define MAYBE_ConstrainedWindowRequest DISABLED_ConstrainedWindowRequest
#else
#define MAYBE_ConstrainedWindowRequest DISABLED_ConstrainedWindowRequest
#endif
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, MAYBE_ConstrainedWindowRequest) {
PermissionsRequestFunction::SetIgnoreUserGestureForTests(true);
const Extension* extension =
LoadAndLaunchPlatformApp("optional_permission_request");
ASSERT_TRUE(extension) << "Failed to load extension.";
WebContents* web_contents = GetFirstAppWindowWebContents();
ASSERT_TRUE(web_contents);
WebContentsModalDialogManager* web_contents_modal_dialog_manager =
WebContentsModalDialogManager::FromWebContents(web_contents);
EXPECT_TRUE(web_contents_modal_dialog_manager->IsDialogActive());
ExtensionTestMessageListener listener("PermissionRequestDone", false);
WebContentsModalDialogManager::TestApi test_api(
web_contents_modal_dialog_manager);
test_api.CloseAllDialogs();
ASSERT_TRUE(listener.WaitUntilSatisfied());
}
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, ReloadRelaunches) {
ExtensionTestMessageListener launched_listener("Launched", true);
const Extension* extension = LoadAndLaunchPlatformApp("reload");
ASSERT_TRUE(extension);
ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
ASSERT_TRUE(GetFirstAppWindow());
ExtensionTestMessageListener launched_listener2("Launched", false);
launched_listener.Reply("reload");
ASSERT_TRUE(launched_listener2.WaitUntilSatisfied());
ASSERT_TRUE(GetFirstAppWindow());
}
namespace {
class CheckExtensionInstalledObserver : public content::NotificationObserver {
public:
CheckExtensionInstalledObserver() : seen_(false) {
registrar_.Add(this,
chrome::NOTIFICATION_EXTENSION_INSTALLED,
content::NotificationService::AllSources());
}
bool seen() const {
return seen_;
};
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE {
EXPECT_FALSE(seen_);
seen_ = true;
}
private:
bool seen_;
content::NotificationRegistrar registrar_;
};
}
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
PRE_PRE_ComponentAppBackgroundPage) {
CheckExtensionInstalledObserver should_install;
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();
ASSERT_TRUE(should_install.seen());
ExtensionTestMessageListener launched_listener("Launched", false);
OpenApplication(AppLaunchParams(
browser()->profile(), extension, LAUNCH_CONTAINER_NONE, NEW_WINDOW));
ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
}
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
PRE_ComponentAppBackgroundPage) {
CheckExtensionInstalledObserver should_not_install;
const Extension* extension = LoadExtensionAsComponent(
test_data_dir_.AppendASCII("platform_apps").AppendASCII("component"));
ASSERT_TRUE(extension);
ExtensionTestMessageListener launched_listener("Launched", false);
OpenApplication(AppLaunchParams(
browser()->profile(), extension, LAUNCH_CONTAINER_NONE, NEW_WINDOW));
ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
ASSERT_FALSE(should_not_install.seen());
ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(browser()->profile());
extensions::ExtensionSystem::Get(browser()->profile())->event_router()->
SetRegisteredEvents(extension->id(), std::set<std::string>());
DictionaryPrefUpdate update(extension_prefs->pref_service(),
extensions::pref_names::kExtensions);
base::DictionaryValue* dict = update.Get();
std::string key(extension->id());
key += ".manifest.version";
dict->SetString(key, "1");
}
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, ComponentAppBackgroundPage) {
CheckExtensionInstalledObserver should_install;
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();
ASSERT_TRUE(should_install.seen());
ExtensionTestMessageListener launched_listener("Launched", false);
OpenApplication(AppLaunchParams(
browser()->profile(), extension, LAUNCH_CONTAINER_NONE, NEW_WINDOW));
ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
}
#if defined(OS_WIN)
#define MAYBE_Messaging DISABLED_Messaging
#else
#define MAYBE_Messaging Messaging
#endif
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, MAYBE_Messaging) {
ExtensionApiTest::ResultCatcher result_catcher;
LoadAndLaunchPlatformApp("messaging/app2");
LoadAndLaunchPlatformApp("messaging/app1");
EXPECT_TRUE(result_catcher.GetNextResult());
}
#if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA)
#define MAYBE_WebContentsHasFocus DISABLED_WebContentsHasFocus
#else
#define MAYBE_WebContentsHasFocus DISABLED_WebContentsHasFocus
#endif
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, MAYBE_WebContentsHasFocus) {
ExtensionTestMessageListener launched_listener("Launched", true);
LoadAndLaunchPlatformApp("minimal");
ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
EXPECT_EQ(1LU, GetAppWindowCount());
EXPECT_TRUE(GetFirstAppWindow()
->web_contents()
->GetRenderWidgetHostView()
->HasFocus());
}
#if !defined(GOOGLE_CHROME_BUILD) || \
(defined(GOOGLE_CHROME_BUILD) && (defined(OS_WIN) || defined(OS_LINUX)))
#define MAYBE_WindowDotPrintShouldBringUpPrintPreview \
DISABLED_WindowDotPrintShouldBringUpPrintPreview
#else
#define MAYBE_WindowDotPrintShouldBringUpPrintPreview \
WindowDotPrintShouldBringUpPrintPreview
#endif
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
MAYBE_WindowDotPrintShouldBringUpPrintPreview) {
ScopedPreviewTestingDelegate preview_delegate(true);
ASSERT_TRUE(RunPlatformAppTest("platform_apps/print_api")) << message_;
preview_delegate.WaitUntilPreviewIsReady();
}
#if !defined(GOOGLE_CHROME_BUILD)
#define MAYBE_ClosingWindowWhilePrintingShouldNotCrash \
DISABLED_ClosingWindowWhilePrintingShouldNotCrash
#else
#define MAYBE_ClosingWindowWhilePrintingShouldNotCrash \
ClosingWindowWhilePrintingShouldNotCrash
#endif
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
MAYBE_ClosingWindowWhilePrintingShouldNotCrash) {
ScopedPreviewTestingDelegate preview_delegate(false);
ASSERT_TRUE(RunPlatformAppTest("platform_apps/print_api")) << message_;
preview_delegate.WaitUntilPreviewIsReady();
GetFirstAppWindow()->GetBaseWindow()->Close();
}
#if !defined(GOOGLE_CHROME_BUILD) || !defined(OS_MACOSX)
#define MAYBE_PrintPreviewShouldNotBeTooSmall \
DISABLED_PrintPreviewShouldNotBeTooSmall
#else
#define MAYBE_PrintPreviewShouldNotBeTooSmall \
PrintPreviewShouldNotBeTooSmall
#endif
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
MAYBE_PrintPreviewShouldNotBeTooSmall) {
gfx::Size minimum_dialog_size(410, 191);
ScopedPreviewTestingDelegate preview_delegate(false);
ASSERT_TRUE(RunPlatformAppTest("platform_apps/print_api")) << message_;
preview_delegate.WaitUntilPreviewIsReady();
EXPECT_GE(preview_delegate.dialog_size().width(),
minimum_dialog_size.width());
EXPECT_GE(preview_delegate.dialog_size().height(),
minimum_dialog_size.height());
GetFirstAppWindow()->GetBaseWindow()->Close();
}
#if defined(OS_CHROMEOS)
class PlatformAppIncognitoBrowserTest : public PlatformAppBrowserTest,
public AppWindowRegistry::Observer {
public:
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
command_line->AppendSwitch(switches::kIncognito);
PlatformAppBrowserTest::SetUpCommandLine(command_line);
}
virtual void SetUp() OVERRIDE {
ComponentLoader::EnableBackgroundExtensionsForTesting();
PlatformAppBrowserTest::SetUp();
}
virtual void OnAppWindowAdded(AppWindow* app_window) OVERRIDE {
opener_app_ids_.insert(app_window->extension()->id());
}
virtual void OnAppWindowIconChanged(AppWindow* app_window) OVERRIDE {}
virtual void OnAppWindowRemoved(AppWindow* app_window) OVERRIDE {}
protected:
std::set<std::string> opener_app_ids_;
};
IN_PROC_BROWSER_TEST_F(PlatformAppIncognitoBrowserTest, IncognitoComponentApp) {
const Extension* file_manager = extension_service()->GetExtensionById(
"hhaomjibdihmijegdhdafkllkbggdgoj", false);
ASSERT_TRUE(file_manager != NULL);
Profile* incognito_profile = profile()->GetOffTheRecordProfile();
ASSERT_TRUE(incognito_profile != NULL);
EventRouter* router = ExtensionSystem::Get(incognito_profile)->event_router();
ASSERT_TRUE(router != NULL);
while (!router->ExtensionHasEventListener(
file_manager->id(), app_runtime::OnLaunched::kEventName)) {
content::RunAllPendingInMessageLoop();
}
AppWindowRegistry* registry = AppWindowRegistry::Get(incognito_profile);
ASSERT_TRUE(registry != NULL);
registry->AddObserver(this);
OpenApplication(AppLaunchParams(
incognito_profile, file_manager, 0, chrome::HOST_DESKTOP_TYPE_NATIVE));
while (!ContainsKey(opener_app_ids_, file_manager->id())) {
content::RunAllPendingInMessageLoop();
}
}
class RestartDeviceTest : public PlatformAppBrowserTest {
public:
RestartDeviceTest()
: power_manager_client_(NULL),
mock_user_manager_(NULL) {}
virtual ~RestartDeviceTest() {}
virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
PlatformAppBrowserTest::SetUpInProcessBrowserTestFixture();
chromeos::FakeDBusThreadManager* dbus_manager =
new chromeos::FakeDBusThreadManager;
dbus_manager->SetFakeClients();
power_manager_client_ = new chromeos::FakePowerManagerClient;
dbus_manager->SetPowerManagerClient(
scoped_ptr<chromeos::PowerManagerClient>(power_manager_client_));
chromeos::DBusThreadManager::SetInstanceForTesting(dbus_manager);
}
virtual void SetUpOnMainThread() OVERRIDE {
PlatformAppBrowserTest::SetUpOnMainThread();
mock_user_manager_ = new chromeos::MockUserManager;
user_manager_enabler_.reset(
new chromeos::ScopedUserManagerEnabler(mock_user_manager_));
EXPECT_CALL(*mock_user_manager_, IsUserLoggedIn())
.WillRepeatedly(testing::Return(true));
EXPECT_CALL(*mock_user_manager_, IsLoggedInAsKioskApp())
.WillRepeatedly(testing::Return(true));
}
virtual void CleanUpOnMainThread() OVERRIDE {
user_manager_enabler_.reset();
PlatformAppBrowserTest::CleanUpOnMainThread();
}
virtual void TearDownInProcessBrowserTestFixture() OVERRIDE {
PlatformAppBrowserTest::TearDownInProcessBrowserTestFixture();
}
int num_request_restart_calls() const {
return power_manager_client_->num_request_restart_calls();
}
private:
chromeos::FakePowerManagerClient* power_manager_client_;
chromeos::MockUserManager* mock_user_manager_;
scoped_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_;
DISALLOW_COPY_AND_ASSIGN(RestartDeviceTest);
};
IN_PROC_BROWSER_TEST_F(RestartDeviceTest, Restart) {
ASSERT_EQ(0, num_request_restart_calls());
ExtensionTestMessageListener launched_listener("Launched", true);
const Extension* extension = LoadAndLaunchPlatformApp("restart_device");
ASSERT_TRUE(extension);
ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
launched_listener.Reply("restart");
ExtensionTestMessageListener restart_requested_listener("restartRequested",
false);
ASSERT_TRUE(restart_requested_listener.WaitUntilSatisfied());
EXPECT_EQ(1, num_request_restart_calls());
}
#endif
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, ReinstallDataCleanup) {
std::string extension_id;
{
ExtensionTestMessageListener launched_listener("Launched", false);
const Extension* extension =
LoadAndLaunchPlatformApp("reinstall_data_cleanup");
ASSERT_TRUE(extension);
extension_id = extension->id();
ExtensionApiTest::ResultCatcher result_catcher;
ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
EXPECT_TRUE(result_catcher.GetNextResult());
}
UninstallExtension(extension_id);
content::RunAllPendingInMessageLoop();
{
ExtensionTestMessageListener launched_listener("Launched", false);
const Extension* extension =
LoadAndLaunchPlatformApp("reinstall_data_cleanup");
ASSERT_TRUE(extension);
ASSERT_EQ(extension_id, extension->id());
ExtensionApiTest::ResultCatcher result_catcher;
ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
EXPECT_TRUE(result_catcher.GetNextResult());
}
}
}