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

Side by Side Diff: content/browser/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: Move test file Created 5 years, 2 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/common/service_registry.h"
7 #include "content/public/test/content_browser_test.h"
8 #include "content/public/test/content_browser_test_utils.h"
9 #include "content/public/test/test_utils.h"
10 #include "content/shell/browser/shell.h"
11 #include "content/shell/browser/shell_content_browser_client.h"
12 #include "device/vibration/vibration_manager.mojom.h"
13 #include "third_party/mojo/src/mojo/public/cpp/bindings/strong_binding.h"
14
15 // These tests run against a dummy implementation of the VibrationManager
16 // service. That is, they verify that the service implementation is correctly
17 // exposed to the renderer, whatever the implementation is.
18
19 namespace content {
20
21 namespace {
22
23 // Global, record milliseconds when Vibrate() got called.
24 int64 g_vibrate_milliseconds;
25 // Global, record whether Cancel() got called.
26 bool g_cancelled;
27 // Global, wait for end of execution for VibrationManager API Vibrate().
28 scoped_refptr<content::MessageLoopRunner> g_wait_vibrate_runner;
29 // Global, wait for end of execution for VibrationManager API Cancel().
30 scoped_refptr<content::MessageLoopRunner> g_wait_cancel_runner;
31
32 void ResetGlobalValues() {
33 g_vibrate_milliseconds = -1;
34 g_cancelled = false;
35
36 g_wait_vibrate_runner = new content::MessageLoopRunner();
37 g_wait_cancel_runner = new content::MessageLoopRunner();
38 }
39
40 class FakeVibrationManager : public device::VibrationManager {
41 public:
42 static void Create(mojo::InterfaceRequest<VibrationManager> request) {
43 new FakeVibrationManager(request.Pass());
44 }
45
46 private:
47 FakeVibrationManager(mojo::InterfaceRequest<VibrationManager> request)
48 : binding_(this, request.Pass()) {}
49 ~FakeVibrationManager() override {}
50
51 void Vibrate(int64 milliseconds) override {
52 g_vibrate_milliseconds = milliseconds;
53 g_wait_vibrate_runner->Quit();
54 }
55
56 void Cancel() override {
57 g_cancelled = true;
58 g_wait_cancel_runner->Quit();
59 }
60
61 mojo::StrongBinding<VibrationManager> binding_;
62 };
63
64 // Overrides the default service implementation with the test implementation
65 // declared above.
66 class TestContentBrowserClient : public ContentBrowserClient {
67 public:
68 void RegisterRenderProcessMojoServices(ServiceRegistry* registry) override {
69 registry->AddService(base::Bind(&FakeVibrationManager::Create));
70 }
71
72 #if defined(OS_ANDROID)
73 void GetAdditionalMappedFilesForChildProcess(
74 const base::CommandLine& command_line,
75 int child_process_id,
76 FileDescriptorInfo* mappings,
77 std::map<int, base::MemoryMappedFile::Region>* regions) override {
78 ShellContentBrowserClient::Get()->GetAdditionalMappedFilesForChildProcess(
79 command_line, child_process_id, mappings, regions);
80 }
81 #endif // defined(OS_ANDROID)
82 };
83
84 class VibrationManagerIntegrationTest : public ContentBrowserTest {
85 public:
86 VibrationManagerIntegrationTest() {}
87
88 void SetUpOnMainThread() override {
89 old_client_ = SetBrowserClientForTesting(&test_client_);
90 ResetGlobalValues();
91 }
92
93 void TearDownOnMainThread() override {
94 SetBrowserClientForTesting(old_client_);
95 }
96
97 private:
98 TestContentBrowserClient test_client_;
99 ContentBrowserClient* old_client_;
100
101 DISALLOW_COPY_AND_ASSIGN(VibrationManagerIntegrationTest);
102 };
103
104 IN_PROC_BROWSER_TEST_F(VibrationManagerIntegrationTest, Vibrate) {
105 // From JavaScript call navigator.vibrate(3000),
106 // then check the global value g_vibrate_milliseconds.
107 ASSERT_EQ(-1, g_vibrate_milliseconds);
108 ASSERT_FALSE(g_wait_vibrate_runner->loop_running());
109
110 GURL test_url =
111 GetTestUrl("vibration", "vibration_manager_vibrate_test.html");
112 shell()->LoadURL(test_url);
113 // Wait until VibrationManager::Vibrate() got called.
114 g_wait_vibrate_runner->Run();
115
116 EXPECT_EQ(3000, g_vibrate_milliseconds);
117 }
118
119 IN_PROC_BROWSER_TEST_F(VibrationManagerIntegrationTest, Cancel) {
120 // From JavaScript call navigator.vibrate(0),
121 // then check the global value g_cancelled.
122 ASSERT_FALSE(g_cancelled);
123 ASSERT_FALSE(g_wait_cancel_runner->loop_running());
124
125 GURL test_url = GetTestUrl("vibration", "vibration_manager_cancel_test.html");
126 shell()->LoadURL(test_url);
127 // Wait until VibrationManager::Cancel() got called.
128 g_wait_cancel_runner->Run();
129
130 EXPECT_TRUE(g_cancelled);
131 }
132
133 } // namespace
134
135 } // 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