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

Side by Side Diff: content/browser/vibration/vibration_manager_integration_browsertest.cc

Issue 1312123003: Add browsertests for //device/vibration. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed tryserver failure Created 5 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
« no previous file with comments | « no previous file | content/content_tests.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 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 "content/public/browser/content_browser_client.h"
6 #include "content/public/browser/web_contents.h"
timvolodine 2015/09/28 15:05:53 is this needed?
leonhsl(Using Gerrit) 2015/09/29 07:28:00 Acknowledged. Removed.
7 #include "content/public/common/content_client.h"
timvolodine 2015/09/28 15:05:53 and this?
leonhsl(Using Gerrit) 2015/09/29 07:28:00 Acknowledged. Removed.
8 #include "content/public/common/service_registry.h"
9 #include "content/public/test/content_browser_test.h"
10 #include "content/public/test/content_browser_test_utils.h"
11 #include "content/public/test/test_utils.h"
12 #include "content/shell/browser/shell.h"
13 #include "content/shell/browser/shell_content_browser_client.h"
14 #include "device/vibration/vibration_manager.mojom.h"
15 #include "third_party/mojo/src/mojo/public/cpp/bindings/strong_binding.h"
16
17 // These tests run against a dummy implementation of the VibrationManager
18 // service.
19 // That is, they verify that the service implementation is correctly exposed to
timvolodine 2015/09/28 15:05:53 nit: maybe put on previous line for better readabi
leonhsl(Using Gerrit) 2015/09/29 07:28:00 Done.
20 // the renderer, whatever the implementation is.
21
22 namespace content {
23
24 namespace {
25
26 // Global, record milliseconds when Vibrate() got called.
27 int64 g_vibrate_milliseconds;
28 // Global, record whether Cancel() got called.
29 bool g_cancelled;
30 // Global, wait for end of execution for VibrationManager API Vibrate().
31 scoped_refptr<content::MessageLoopRunner> g_wait_vibrate_runner;
32 // Global, wait for end of execution for VibrationManager API Cancel().
33 scoped_refptr<content::MessageLoopRunner> g_wait_cancel_runner;
34
35 void ResetGlobalValues() {
36 g_vibrate_milliseconds = -1;
37 g_cancelled = false;
38
39 g_wait_vibrate_runner = new content::MessageLoopRunner();
40 g_wait_cancel_runner = new content::MessageLoopRunner();
41 }
42
43 class FakeVibrationManager : public device::VibrationManager {
44 public:
45 static void Create(mojo::InterfaceRequest<VibrationManager> request) {
46 new FakeVibrationManager(request.Pass());
47 }
48
49 private:
50 FakeVibrationManager(mojo::InterfaceRequest<VibrationManager> request)
51 : binding_(this, request.Pass()) {}
52 ~FakeVibrationManager() override {}
53
54 void Vibrate(int64 milliseconds) override {
55 g_vibrate_milliseconds = milliseconds;
56 g_wait_vibrate_runner->Quit();
57 }
58
59 void Cancel() override {
60 g_cancelled = true;
61 g_wait_cancel_runner->Quit();
62 }
63
64 mojo::StrongBinding<VibrationManager> binding_;
65 };
66
67 // Overrides the default service implementation with the test implementation
68 // declared above.
69 class TestContentBrowserClient : public ContentBrowserClient {
70 public:
71 void RegisterRenderProcessMojoServices(ServiceRegistry* registry) override {
72 registry->AddService(base::Bind(&FakeVibrationManager::Create));
73 }
74
75 #if defined(OS_ANDROID)
76 void GetAdditionalMappedFilesForChildProcess(
77 const base::CommandLine& command_line,
78 int child_process_id,
79 FileDescriptorInfo* mappings,
80 std::map<int, base::MemoryMappedFile::Region>* regions) override {
81 ShellContentBrowserClient::Get()->GetAdditionalMappedFilesForChildProcess(
82 command_line, child_process_id, mappings, regions);
83 }
84 #endif // defined(OS_ANDROID)
85 };
86
87 class VibrationManagerIntegrationTest : public ContentBrowserTest {
88 public:
89 VibrationManagerIntegrationTest() {}
90
91 void SetUpOnMainThread() override {
92 old_client_ = SetBrowserClientForTesting(&test_client_);
93 }
94
95 void TearDownOnMainThread() override {
96 SetBrowserClientForTesting(old_client_);
97 }
98
99 private:
100 TestContentBrowserClient test_client_;
101 ContentBrowserClient* old_client_;
102
103 DISALLOW_COPY_AND_ASSIGN(VibrationManagerIntegrationTest);
104 };
105
106 IN_PROC_BROWSER_TEST_F(VibrationManagerIntegrationTest, Vibrate) {
107 // From JavaScript call navigator.vibrate(3000),
108 // then check the global value g_vibrate_milliseconds.
109 ResetGlobalValues();
timvolodine 2015/09/28 15:05:53 should this be in SetUp somewhere?
leonhsl(Using Gerrit) 2015/09/29 07:28:00 Acknowledged. Moved into SetUpOnMainThread().
110 ASSERT_EQ(-1, g_vibrate_milliseconds);
111 ASSERT_FALSE(g_wait_vibrate_runner->loop_running());
112
113 GURL test_url =
114 GetTestUrl("vibration", "vibration_manager_vibrate_test.html");
115 shell()->LoadURL(test_url);
116 // Wait until VibrationManager::Vibrate() got called.
117 g_wait_vibrate_runner->Run();
timvolodine 2015/09/11 17:44:04 would base::WaitableEvent be a cleaner solution he
leonhsl(Using Gerrit) 2015/09/14 10:35:34 Because both browser test code and the VibrationMa
timvolodine 2015/09/28 15:05:53 ok
118
119 EXPECT_EQ(3000, g_vibrate_milliseconds);
120 }
121
122 IN_PROC_BROWSER_TEST_F(VibrationManagerIntegrationTest, Cancel) {
123 // From JavaScript call navigator.vibrate(0),
124 // then check the global value g_cancelled.
125 ResetGlobalValues();
timvolodine 2015/09/28 15:05:53 same question
leonhsl(Using Gerrit) 2015/09/29 07:28:00 Acknowledged. Moved into SetUpOnMainThread().
126 ASSERT_FALSE(g_cancelled);
127 ASSERT_FALSE(g_wait_cancel_runner->loop_running());
128
129 GURL test_url = GetTestUrl("vibration", "vibration_manager_cancel_test.html");
130 shell()->LoadURL(test_url);
131 // Wait until VibrationManager::Cancel() got called.
132 g_wait_cancel_runner->Run();
133
134 EXPECT_TRUE(g_cancelled);
135 }
136
137 } // namespace
138
139 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/content_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698