| 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/thread_task_runner_handle.h" | 7 #include "base/thread_task_runner_handle.h" |
| 8 #include "content/public/browser/content_browser_client.h" | 8 #include "content/public/browser/content_browser_client.h" |
| 9 #include "content/public/browser/web_contents.h" | 9 #include "content/public/browser/web_contents.h" |
| 10 #include "content/public/common/content_client.h" | 10 #include "content/public/common/content_client.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 } | 44 } |
| 45 | 45 |
| 46 class FakeBatteryMonitor : public device::BatteryMonitor { | 46 class FakeBatteryMonitor : public device::BatteryMonitor { |
| 47 public: | 47 public: |
| 48 static void Create(mojo::InterfaceRequest<BatteryMonitor> request) { | 48 static void Create(mojo::InterfaceRequest<BatteryMonitor> request) { |
| 49 new FakeBatteryMonitor(request.Pass()); | 49 new FakeBatteryMonitor(request.Pass()); |
| 50 } | 50 } |
| 51 | 51 |
| 52 private: | 52 private: |
| 53 FakeBatteryMonitor(mojo::InterfaceRequest<BatteryMonitor> request) | 53 FakeBatteryMonitor(mojo::InterfaceRequest<BatteryMonitor> request) |
| 54 : subscription_( | 54 : binding_(this, request.Pass()) { |
| 55 g_callback_list.Get().Add(base::Bind(&FakeBatteryMonitor::DidChange, | |
| 56 base::Unretained(this)))), | |
| 57 binding_(this, request.Pass()) { | |
| 58 DidChange(g_battery_status); | |
| 59 } | 55 } |
| 60 ~FakeBatteryMonitor() override {} | 56 ~FakeBatteryMonitor() override {} |
| 61 | 57 |
| 62 void DidChange(const device::BatteryStatus& battery_status) { | 58 void SetClient(device::BatteryMonitorClientPtr client) override { |
| 63 device::BatteryStatusPtr status(device::BatteryStatus::New()); | 59 client_ = client.Pass(); |
| 64 *status = battery_status; | 60 subscription_ = |
| 65 binding_.client()->DidChange(status.Pass()); | 61 g_callback_list.Get().Add( |
| 62 base::Bind(&FakeBatteryMonitor::DidChange, base::Unretained(this))); |
| 63 DidChange(g_battery_status); |
| 66 } | 64 } |
| 67 | 65 |
| 66 void DidChange(const device::BatteryStatus& battery_status) { |
| 67 client_->DidChange(battery_status.Clone()); |
| 68 } |
| 69 |
| 70 device::BatteryMonitorClientPtr client_; |
| 68 scoped_ptr<BatteryUpdateSubscription> subscription_; | 71 scoped_ptr<BatteryUpdateSubscription> subscription_; |
| 69 mojo::StrongBinding<BatteryMonitor> binding_; | 72 mojo::StrongBinding<BatteryMonitor> binding_; |
| 70 }; | 73 }; |
| 71 | 74 |
| 72 // Overrides the default service implementation with the test implementation | 75 // Overrides the default service implementation with the test implementation |
| 73 // declared above. | 76 // declared above. |
| 74 class TestContentBrowserClient : public ContentBrowserClient { | 77 class TestContentBrowserClient : public ContentBrowserClient { |
| 75 public: | 78 public: |
| 76 void OverrideRenderProcessMojoServices(ServiceRegistry* registry) override { | 79 void OverrideRenderProcessMojoServices(ServiceRegistry* registry) override { |
| 77 registry->AddService(base::Bind(&FakeBatteryMonitor::Create)); | 80 registry->AddService(base::Bind(&FakeBatteryMonitor::Create)); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 TestNavigationObserver same_tab_observer2(shell()->web_contents(), 1); | 146 TestNavigationObserver same_tab_observer2(shell()->web_contents(), 1); |
| 144 status.level = 0.6; | 147 status.level = 0.6; |
| 145 UpdateBattery(status); | 148 UpdateBattery(status); |
| 146 same_tab_observer2.Wait(); | 149 same_tab_observer2.Wait(); |
| 147 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); | 150 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); |
| 148 } | 151 } |
| 149 | 152 |
| 150 } // namespace | 153 } // namespace |
| 151 | 154 |
| 152 } // namespace content | 155 } // namespace content |
| OLD | NEW |