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

Side by Side Diff: extensions/browser/guest_view/web_view/web_view_browsertests.cc

Issue 581283002: Add webview testAPIMethodExistence to app_shell_browsertests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months 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.
Yoyo Zhou 2014/09/19 00:26:03 Even if you have multiple tests, this file should
lfg 2014/09/22 17:44:27 What about web_view_apitest.cc ?
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_utils.h"
8 #include "content/public/test/test_utils.h"
9 #include "extensions/browser/app_window/app_window.h"
10 #include "extensions/browser/app_window/app_window_registry.h"
11 #include "extensions/browser/extension_host.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/process_manager.h"
15 #include "extensions/common/extension.h"
16 #include "extensions/common/extension_paths.h"
17 #include "extensions/shell/browser/shell_extension_system.h"
18 #include "extensions/shell/test/shell_test.h"
19 #include "extensions/test/extension_test_message_listener.h"
20
21 namespace {
22
23 class TestGuestViewManager : public extensions::GuestViewManager {
Yoyo Zhou 2014/09/19 00:26:03 This looks very similar to the other web_view_brow
lfg 2014/09/22 17:44:27 They are the same. I've added a TODO to merge them
24 public:
25 explicit TestGuestViewManager(content::BrowserContext* context)
26 : GuestViewManager(context),
27 seen_guest_removed_(false),
28 web_contents_(NULL) {}
29
30 content::WebContents* WaitForGuestCreated() {
31 if (web_contents_)
32 return web_contents_;
33
34 created_message_loop_runner_ = new content::MessageLoopRunner;
35 created_message_loop_runner_->Run();
36 return web_contents_;
37 }
38
39 void WaitForGuestDeleted() {
40 if (seen_guest_removed_)
41 return;
42
43 deleted_message_loop_runner_ = new content::MessageLoopRunner;
44 deleted_message_loop_runner_->Run();
45 }
46
47 private:
48 // GuestViewManager override:
49 virtual void AddGuest(int guest_instance_id,
50 content::WebContents* guest_web_contents) OVERRIDE {
51 extensions::GuestViewManager::AddGuest(guest_instance_id,
52 guest_web_contents);
53 web_contents_ = guest_web_contents;
54 seen_guest_removed_ = false;
55
56 if (created_message_loop_runner_.get())
57 created_message_loop_runner_->Quit();
58 }
59
60 virtual void RemoveGuest(int guest_instance_id) OVERRIDE {
61 extensions::GuestViewManager::RemoveGuest(guest_instance_id);
62 web_contents_ = NULL;
63 seen_guest_removed_ = true;
64
65 if (deleted_message_loop_runner_.get())
66 deleted_message_loop_runner_->Quit();
67 }
68
69 bool seen_guest_removed_;
70 content::WebContents* web_contents_;
71 scoped_refptr<content::MessageLoopRunner> created_message_loop_runner_;
72 scoped_refptr<content::MessageLoopRunner> deleted_message_loop_runner_;
73 };
74
75 // Test factory for creating test instances of GuestViewManager.
76 class TestGuestViewManagerFactory : public extensions::GuestViewManagerFactory {
77 public:
78 TestGuestViewManagerFactory() : test_guest_view_manager_(NULL) {}
79
80 virtual ~TestGuestViewManagerFactory() {}
81
82 virtual extensions::GuestViewManager* CreateGuestViewManager(
83 content::BrowserContext* context) OVERRIDE {
84 return GetManager(context);
85 }
86
87 TestGuestViewManager* GetManager(content::BrowserContext* context) {
88 if (!test_guest_view_manager_) {
89 test_guest_view_manager_ = new TestGuestViewManager(context);
90 }
91 return test_guest_view_manager_;
92 }
93
94 private:
95 TestGuestViewManager* test_guest_view_manager_;
Yoyo Zhou 2014/09/19 00:26:04 scoped_ptr? (How does this get deleted?)
lfg 2014/09/22 17:44:27 Good question, I copied this code from the other f
96
97 DISALLOW_COPY_AND_ASSIGN(TestGuestViewManagerFactory);
98 };
99
100 } // namespace
101
102 namespace extensions {
103
104 // This class intercepts download request from the guest.
105 class WebViewTest : public AppShellTest {
106 protected:
107 void TestHelper(const std::string& test_name,
Yoyo Zhou 2014/09/19 00:26:03 This name isn't very descriptive. It could be bett
lfg 2014/09/22 17:44:27 Done.
108 const std::string& app_location) {
109 std::cout << "Launching test " << test_name << " from " << app_location
Yoyo Zhou 2014/09/19 00:26:03 remove debug comments or change them to VLOG/DVLOG
lfg 2014/09/22 17:44:27 Forgot those. Removed.
110 << std::endl;
111
112 base::FilePath test_data_dir;
113 PathService::Get(extensions::DIR_TEST_DATA, &test_data_dir);
114 test_data_dir = test_data_dir.AppendASCII(app_location.c_str());
115
116 bool loaded = extension_system_->LoadApp(test_data_dir);
117 ASSERT_TRUE(loaded);
Yoyo Zhou 2014/09/19 00:26:03 inline with previous line
lfg 2014/09/22 17:44:27 Done.
118 extension_system_->LaunchApp();
119
120 ExtensionTestMessageListener launch_listener("LAUNCHED", false);
121 ASSERT_TRUE(launch_listener.WaitUntilSatisfied());
122
123 const AppWindowRegistry::AppWindowList& app_window_list =
124 AppWindowRegistry::Get(browser_context_)->app_windows();
125 if (app_window_list.empty()) {
126 LOG(ERROR) << "UNABLE TO FIND EMBEDDER WEB CONTENTS.";
Yoyo Zhou 2014/09/19 00:26:04 All caps doesn't seem necessary.
lfg 2014/09/22 17:44:27 I've changed it to a DCHECK, as per fsamuel@ sugge
127 return;
128 }
129 content::WebContents* embedder_web_contents =
Fady Samuel 2014/09/18 23:22:14 Can we add a DCHECK above to verify there is exact
lfg 2014/09/22 17:44:27 Done.
130 (*app_window_list.begin())->web_contents();
131
132 ExtensionTestMessageListener done_listener("TEST_PASSED", false);
133 done_listener.set_failure_message("TEST_FAILED");
134 if (!content::ExecuteScript(
135 embedder_web_contents,
136 base::StringPrintf("runTest('%s')", test_name.c_str()))) {
137 LOG(ERROR) << "UNABLE TO START TEST.";
138 return;
139 }
140 ASSERT_TRUE(done_listener.WaitUntilSatisfied());
141 }
142
143 WebViewTest() {
144 extensions::GuestViewManager::set_factory_for_testing(&factory_);
145 }
146
147 private:
148 TestGuestViewManagerFactory factory_;
149 };
150
151 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestAPIMethodExistence) {
Yoyo Zhou 2014/09/19 00:26:03 Shim looks like it's in a strange place in this na
lfg 2014/09/22 17:44:27 I originally copied from the chrome browsertests.
152 TestHelper("testAPIMethodExistence", "web_view/shim");
153 }
154
155 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | extensions/shell/app_shell.gyp » ('j') | extensions/test/data/web_view/shim/main.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698