Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/callback_list.h" | 5 #include "base/callback_list.h" |
| 6 #include "base/lazy_instance.h" | 6 #include "base/lazy_instance.h" |
| 7 #include "base/path_service.h" | |
| 7 #include "base/thread_task_runner_handle.h" | 8 #include "base/thread_task_runner_handle.h" |
| 8 #include "content/public/browser/content_browser_client.h" | 9 #include "content/public/browser/content_browser_client.h" |
| 9 #include "content/public/browser/web_contents.h" | 10 #include "content/public/browser/web_contents.h" |
| 10 #include "content/public/common/content_client.h" | 11 #include "content/public/common/content_client.h" |
| 11 #include "content/public/common/service_registry.h" | 12 #include "content/public/common/service_registry.h" |
| 12 #include "content/public/test/content_browser_test.h" | 13 #include "content/public/test/content_browser_test.h" |
| 13 #include "content/public/test/content_browser_test_utils.h" | 14 #include "content/public/test/content_browser_test_utils.h" |
| 14 #include "content/public/test/test_navigation_observer.h" | 15 #include "content/public/test/test_navigation_observer.h" |
| 15 #include "content/public/test/test_utils.h" | 16 #include "content/public/test/test_utils.h" |
| 17 #if defined(OS_ANDROID) | |
|
ppi
2015/01/21 00:33:50
Jochen will correct me if I'm wrong, but I thing w
| |
| 18 #include "content/shell/android/shell_descriptors.h" | |
| 19 #endif | |
| 16 #include "content/shell/browser/shell.h" | 20 #include "content/shell/browser/shell.h" |
| 17 #include "content/shell/browser/shell_content_browser_client.h" | 21 #include "content/shell/browser/shell_content_browser_client.h" |
| 18 #include "device/battery/battery_monitor.mojom.h" | 22 #include "device/battery/battery_monitor.mojom.h" |
| 19 #include "mojo/public/cpp/bindings/strong_binding.h" | 23 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 20 | 24 |
| 21 // These tests run against a dummy implementation of the BatteryMonitor service. | 25 // These tests run against a dummy implementation of the BatteryMonitor service. |
| 22 // That is, they verify that the service implementation is correctly exposed to | 26 // That is, they verify that the service implementation is correctly exposed to |
| 23 // the renderer, whatever the implementation is. | 27 // the renderer, whatever the implementation is. |
| 24 | 28 |
| 25 namespace content { | 29 namespace content { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 BatteryStatusCallback callback_; | 88 BatteryStatusCallback callback_; |
| 85 }; | 89 }; |
| 86 | 90 |
| 87 // Overrides the default service implementation with the test implementation | 91 // Overrides the default service implementation with the test implementation |
| 88 // declared above. | 92 // declared above. |
| 89 class TestContentBrowserClient : public ContentBrowserClient { | 93 class TestContentBrowserClient : public ContentBrowserClient { |
| 90 public: | 94 public: |
| 91 void OverrideRenderProcessMojoServices(ServiceRegistry* registry) override { | 95 void OverrideRenderProcessMojoServices(ServiceRegistry* registry) override { |
| 92 registry->AddService(base::Bind(&FakeBatteryMonitor::Create)); | 96 registry->AddService(base::Bind(&FakeBatteryMonitor::Create)); |
| 93 } | 97 } |
| 98 #if defined(OS_ANDROID) | |
| 99 void GetAdditionalMappedFilesForChildProcess( | |
|
ppi
2015/01/21 00:33:50
We shouldn't duplicate the code from ShellContentB
| |
| 100 const base::CommandLine& command_line, | |
| 101 int child_process_id, | |
| 102 FileDescriptorInfo* mappings) override { | |
| 103 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ; | |
| 104 base::FilePath pak_file; | |
| 105 bool r = PathService::Get(base::DIR_ANDROID_APP_DATA, &pak_file); | |
| 106 CHECK(r); | |
| 107 pak_file = pak_file.Append(FILE_PATH_LITERAL("paks")); | |
| 108 pak_file = pak_file.Append(FILE_PATH_LITERAL("content_shell.pak")); | |
| 109 | |
| 110 base::File f(pak_file, flags); | |
| 111 if (!f.IsValid()) { | |
| 112 NOTREACHED() << "Failed to open file when creating renderer process: " | |
| 113 << "content_shell.pak"; | |
| 114 } | |
| 115 | |
| 116 mappings->Transfer(kShellPakDescriptor, | |
| 117 base::ScopedFD(f.TakePlatformFile())); | |
| 118 } | |
| 119 #endif // defined(OS_ANDROID) | |
| 94 }; | 120 }; |
| 95 | 121 |
| 96 class BatteryMonitorIntegrationTest : public ContentBrowserTest { | 122 class BatteryMonitorIntegrationTest : public ContentBrowserTest { |
| 97 public: | 123 public: |
| 98 BatteryMonitorIntegrationTest() {} | 124 BatteryMonitorIntegrationTest() {} |
| 99 | 125 |
| 100 void SetUpOnMainThread() override { | 126 void SetUpOnMainThread() override { |
| 101 old_client_ = SetBrowserClientForTesting(&test_client_); | 127 old_client_ = SetBrowserClientForTesting(&test_client_); |
| 102 } | 128 } |
| 103 | 129 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 158 TestNavigationObserver same_tab_observer2(shell()->web_contents(), 1); | 184 TestNavigationObserver same_tab_observer2(shell()->web_contents(), 1); |
| 159 status.level = 0.6; | 185 status.level = 0.6; |
| 160 UpdateBattery(status); | 186 UpdateBattery(status); |
| 161 same_tab_observer2.Wait(); | 187 same_tab_observer2.Wait(); |
| 162 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); | 188 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); |
| 163 } | 189 } |
| 164 | 190 |
| 165 } // namespace | 191 } // namespace |
| 166 | 192 |
| 167 } // namespace content | 193 } // namespace content |
| OLD | NEW |