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

Side by Side Diff: extensions/browser/guest_view/app_view/app_view_apitest.cc

Issue 643703007: Adding app_view tests to app_shell_browsertests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@multiple_apps
Patch Set: Created 6 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 unified diff | Download patch
OLDNEW
(Empty)
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 "base/path_service.h"
6 #include "base/strings/stringprintf.h"
7 #include "content/public/test/browser_test.h"
8 #include "content/public/test/browser_test_utils.h"
9 #include "content/public/test/test_utils.h"
10 #include "extensions/browser/app_window/app_window.h"
11 #include "extensions/browser/app_window/app_window_registry.h"
12 #include "extensions/browser/guest_view/guest_view_manager.h"
13 #include "extensions/browser/guest_view/guest_view_manager_factory.h"
14 #include "extensions/browser/guest_view/test_guest_view_manager.h"
15 #include "extensions/common/extension.h"
16 #include "extensions/common/extension_paths.h"
17 #include "extensions/shell/browser/shell_content_browser_client.h"
18 #include "extensions/shell/browser/shell_extension_system.h"
19 #include "extensions/shell/test/shell_test.h"
20 #include "extensions/test/extension_test_message_listener.h"
21 #include "net/base/filename_util.h"
22
23 namespace extensions {
24
25 class AppViewTest : public AppShellTest {
26 protected:
27 AppViewTest() {
28 extensions::GuestViewManager::set_factory_for_testing(&factory_);
29 }
30
31 TestGuestViewManager* GetGuestViewManager() {
32 return static_cast<TestGuestViewManager*>(
33 TestGuestViewManager::FromBrowserContext(
34 ShellContentBrowserClient::Get()->GetBrowserContext()));
35 }
36
37 content::WebContents* GetFirstAppWindowWebContents() {
38 const AppWindowRegistry::AppWindowList& app_window_list =
39 AppWindowRegistry::Get(browser_context_)->app_windows();
40 DCHECK(app_window_list.size() == 1);
41 return (*app_window_list.begin())->web_contents();
42 }
43
44 const Extension* LoadApp(const std::string& app_location) {
45 base::FilePath test_data_dir;
46 PathService::Get(DIR_TEST_DATA, &test_data_dir);
47 test_data_dir = test_data_dir.AppendASCII(app_location.c_str());
48 const Extension* extension = extension_system_->LoadApp(test_data_dir);
lazyboy 2014/10/24 20:13:24 nit: return extension_system_->LoadApp ..
lfg 2014/10/24 20:24:29 Done.
49
50 return extension;
51 }
52
53 void RunTest(const std::string& test_name,
54 const std::string& app_location,
55 const std::string& app_to_embed) {
56 extension_system_->Init();
57
58 const Extension* app_embedder = LoadApp(app_location);
59 ASSERT_TRUE(app_embedder);
60 const Extension* app_embedded = LoadApp(app_to_embed);
61 ASSERT_TRUE(app_embedded);
62
63 extension_system_->LaunchApp(app_embedder->id());
64
65 ExtensionTestMessageListener launch_listener("LAUNCHED", false);
66 ASSERT_TRUE(launch_listener.WaitUntilSatisfied());
67
68 embedder_web_contents_ = GetFirstAppWindowWebContents();
69
70 ExtensionTestMessageListener done_listener("TEST_PASSED", false);
71 done_listener.set_failure_message("TEST_FAILED");
72 if (!content::ExecuteScript(
73 embedder_web_contents_,
74 base::StringPrintf("runTest('%s', '%s')",
75 test_name.c_str(),
76 app_embedded->id().c_str()))) {
77 LOG(ERROR) << "Unable to start test.";
78 return;
79 }
80 ASSERT_TRUE(done_listener.WaitUntilSatisfied());
81 }
82
83 protected:
84 content::WebContents* embedder_web_contents_;
85 TestGuestViewManagerFactory factory_;
86 };
87
88 // Tests that <appview> correctly processes parameters passed on connect.
89 IN_PROC_BROWSER_TEST_F(AppViewTest, TestAppViewGoodDataShouldSucceed) {
90 RunTest("testAppViewGoodDataShouldSucceed",
91 "app_view/apitest",
92 "app_view/apitest/skeleton");
93 }
94
95 // Tests that <appview> correctly processes parameters passed on connect.
lazyboy 2014/10/24 20:13:24 Add a bit more test specific comment here, i.e. po
lfg 2014/10/24 20:24:29 Done.
96 IN_PROC_BROWSER_TEST_F(AppViewTest, TestAppViewRefusedDataShouldFail) {
97 RunTest("testAppViewRefusedDataShouldFail",
98 "app_view/apitest",
99 "app_view/apitest/skeleton");
100 }
101
102 // Tests that <appview> is able to navigate to another installed app.
103 IN_PROC_BROWSER_TEST_F(AppViewTest, TestAppViewWithUndefinedDataShouldSucceed) {
104 RunTest("testAppViewWithUndefinedDataShouldSucceed",
105 "app_view/apitest",
106 "app_view/apitest/skeleton");
107 }
108
109 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | extensions/shell/app_shell.gyp » ('j') | extensions/test/data/app_view/apitest/main.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698