shell_test.cc revision 5f1c94371a64b3196d4be9466099bb892df9b88e
1// Copyright 2014 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "extensions/shell/test/shell_test.h"
6
7#include "base/command_line.h"
8#include "base/files/file_path.h"
9#include "base/logging.h"
10#include "content/public/common/content_switches.h"
11#include "extensions/browser/extension_system.h"
12#include "extensions/shell/browser/shell_content_browser_client.h"
13#include "extensions/shell/browser/shell_desktop_controller.h"
14#include "extensions/shell/browser/shell_extension_system.h"
15
16namespace extensions {
17
18AppShellTest::AppShellTest() : browser_context_(NULL), extension_system_(NULL) {
19}
20
21AppShellTest::~AppShellTest() {
22}
23
24void AppShellTest::SetUp() {
25  base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
26  command_line->AppendSwitchASCII(switches::kTestType, "appshell");
27  content::BrowserTestBase::SetUp();
28}
29
30void AppShellTest::SetUpOnMainThread() {
31  browser_context_ = ShellContentBrowserClient::Get()->GetBrowserContext();
32
33  extension_system_ = static_cast<ShellExtensionSystem*>(
34      ExtensionSystem::Get(browser_context_));
35}
36
37void AppShellTest::RunTestOnMainThreadLoop() {
38  base::MessageLoopForUI::current()->RunUntilIdle();
39
40  SetUpOnMainThread();
41
42  RunTestOnMainThread();
43
44  TearDownOnMainThread();
45
46  // Clean up the app window.
47  ShellDesktopController::instance()->CloseAppWindows();
48}
49
50bool AppShellTest::LoadAndLaunchApp(const base::FilePath& app_dir) {
51  bool loaded = extension_system_->LoadApp(app_dir);
52  if (loaded)
53    extension_system_->LaunchApp();
54  return loaded;
55}
56
57}  // namespace extensions
58