| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/test/test_timeouts.h" | 6 #include "base/test/test_timeouts.h" |
| 7 #include "content/browser/wake_lock/wake_lock_service_context.h" | 7 #include "content/browser/wake_lock/wake_lock_service_context.h" |
| 8 #include "content/browser/web_contents/web_contents_impl.h" | 8 #include "content/browser/web_contents/web_contents_impl.h" |
| 9 #include "content/public/common/content_switches.h" | 9 #include "content/public/common/content_switches.h" |
| 10 #include "content/public/test/browser_test_utils.h" | 10 #include "content/public/test/browser_test_utils.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 return GetWebContentsImpl()->GetWakeLockServiceContext(); | 66 return GetWebContentsImpl()->GetWakeLockServiceContext(); |
| 67 } | 67 } |
| 68 | 68 |
| 69 bool HasWakeLock() { | 69 bool HasWakeLock() { |
| 70 return GetWakeLockServiceContext()->HasWakeLockForTests(); | 70 return GetWakeLockServiceContext()->HasWakeLockForTests(); |
| 71 } | 71 } |
| 72 | 72 |
| 73 void WaitForPossibleUpdate() { | 73 void WaitForPossibleUpdate() { |
| 74 // As Mojo channels have no common FIFO order in respect to each other and | 74 // As Mojo channels have no common FIFO order in respect to each other and |
| 75 // to the Chromium IPC, we cannot assume that when screen.keepAwake state | 75 // to the Chromium IPC, we cannot assume that when screen.keepAwake state |
| 76 // is changed from within a script, WakeLockService will receive an update | 76 // is changed from within a script, mojom::WakeLockService will receive an |
| 77 // request before ExecuteScript() returns. Therefore, some time slack is | 77 // update request before ExecuteScript() returns. Therefore, some time slack |
| 78 // needed to make sure that WakeLockService has received any possible update | 78 // is needed to make sure that mojom::WakeLockService has received any |
| 79 // requests before checking the resulting wake lock state. | 79 // possible update requests before checking the resulting wake lock state. |
| 80 base::PlatformThread::Sleep(TestTimeouts::tiny_timeout()); | 80 base::PlatformThread::Sleep(TestTimeouts::tiny_timeout()); |
| 81 RunAllPendingInMessageLoop(); | 81 RunAllPendingInMessageLoop(); |
| 82 } | 82 } |
| 83 | 83 |
| 84 void ScreenWakeLockInMainFrame() { | 84 void ScreenWakeLockInMainFrame() { |
| 85 EXPECT_TRUE(ExecuteScript(GetMainFrame(), "screen.keepAwake = true;")); | 85 EXPECT_TRUE(ExecuteScript(GetMainFrame(), "screen.keepAwake = true;")); |
| 86 WaitForPossibleUpdate(); | 86 WaitForPossibleUpdate(); |
| 87 EXPECT_TRUE(HasWakeLock()); | 87 EXPECT_TRUE(HasWakeLock()); |
| 88 } | 88 } |
| 89 | 89 |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 GetNestedFrame()->GetProcess(), | 367 GetNestedFrame()->GetProcess(), |
| 368 RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); | 368 RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); |
| 369 GetNestedFrame()->GetProcess()->Shutdown(0, false); | 369 GetNestedFrame()->GetProcess()->Shutdown(0, false); |
| 370 watcher.Wait(); | 370 watcher.Wait(); |
| 371 | 371 |
| 372 // Screen wake lock should be released. | 372 // Screen wake lock should be released. |
| 373 EXPECT_FALSE(HasWakeLock()); | 373 EXPECT_FALSE(HasWakeLock()); |
| 374 } | 374 } |
| 375 | 375 |
| 376 } // namespace content | 376 } // namespace content |
| OLD | NEW |