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/web_contents/web_contents_impl.h" | 7 #include "content/browser/web_contents/web_contents_impl.h" |
8 #include "content/public/common/content_switches.h" | 8 #include "content/public/common/content_switches.h" |
9 #include "content/public/test/browser_test_utils.h" | 9 #include "content/public/test/browser_test_utils.h" |
10 #include "content/public/test/content_browser_test.h" | 10 #include "content/public/test/content_browser_test.h" |
11 #include "content/public/test/content_browser_test_utils.h" | 11 #include "content/public/test/content_browser_test_utils.h" |
12 #include "content/public/test/test_utils.h" | 12 #include "content/public/test/test_utils.h" |
13 #include "content/shell/browser/shell.h" | 13 #include "content/shell/browser/shell.h" |
14 #include "content/test/content_browser_test_utils_internal.h" | 14 #include "content/test/content_browser_test_utils_internal.h" |
15 #include "device/wake_lock/wake_lock_service_context.h" | |
16 #include "net/dns/mock_host_resolver.h" | 15 #include "net/dns/mock_host_resolver.h" |
17 #include "net/test/embedded_test_server/embedded_test_server.h" | 16 #include "net/test/embedded_test_server/embedded_test_server.h" |
18 | 17 |
19 namespace content { | 18 namespace content { |
20 | 19 |
21 namespace { | 20 namespace { |
22 | 21 |
23 const char kBlinkWakeLockFeature[] = "WakeLock"; | 22 const char kBlinkWakeLockFeature[] = "WakeLock"; |
24 | 23 |
| 24 void OnHasWakeLock(bool* out, bool has_wakelock) { |
| 25 *out = has_wakelock; |
| 26 base::MessageLoop::current()->QuitNow(); |
| 27 } |
| 28 |
25 } // namespace | 29 } // namespace |
26 | 30 |
27 class WakeLockTest : public ContentBrowserTest { | 31 class WakeLockTest : public ContentBrowserTest { |
28 public: | 32 public: |
29 void SetUpCommandLine(base::CommandLine* command_line) override { | 33 void SetUpCommandLine(base::CommandLine* command_line) override { |
30 command_line->AppendSwitchASCII(switches::kEnableBlinkFeatures, | 34 command_line->AppendSwitchASCII(switches::kEnableBlinkFeatures, |
31 kBlinkWakeLockFeature); | 35 kBlinkWakeLockFeature); |
32 command_line->AppendSwitch(switches::kSitePerProcess); | 36 command_line->AppendSwitch(switches::kSitePerProcess); |
33 } | 37 } |
34 | 38 |
(...skipping 20 matching lines...) Expand all Loading... |
55 FrameTreeNode* GetNestedFrameNode() { | 59 FrameTreeNode* GetNestedFrameNode() { |
56 FrameTreeNode* root = GetWebContentsImpl()->GetFrameTree()->root(); | 60 FrameTreeNode* root = GetWebContentsImpl()->GetFrameTree()->root(); |
57 CHECK_EQ(1U, root->child_count()); | 61 CHECK_EQ(1U, root->child_count()); |
58 return root->child_at(0); | 62 return root->child_at(0); |
59 } | 63 } |
60 | 64 |
61 RenderFrameHost* GetNestedFrame() { | 65 RenderFrameHost* GetNestedFrame() { |
62 return GetNestedFrameNode()->current_frame_host(); | 66 return GetNestedFrameNode()->current_frame_host(); |
63 } | 67 } |
64 | 68 |
65 device::WakeLockServiceContext* GetWakeLockServiceContext() { | 69 device::mojom::WakeLockContext* GetWakeLockServiceContext() { |
66 return GetWebContentsImpl()->GetWakeLockServiceContext(); | 70 return GetWebContentsImpl()->GetWakeLockServiceContext(); |
67 } | 71 } |
68 | 72 |
69 bool HasWakeLock() { | 73 bool HasWakeLock() { |
70 return GetWakeLockServiceContext()->HasWakeLockForTests(); | 74 bool has_wakelock = false; |
| 75 base::RunLoop run_loop; |
| 76 |
| 77 GetWakeLockServiceContext()->HasWakeLockForTests( |
| 78 base::Bind(&OnHasWakeLock, &has_wakelock)); |
| 79 run_loop.Run(); |
| 80 return has_wakelock; |
71 } | 81 } |
72 | 82 |
73 void WaitForPossibleUpdate() { | 83 void WaitForPossibleUpdate() { |
74 // As Mojo channels have no common FIFO order in respect to each other and | 84 // 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 | 85 // to the Chromium IPC, we cannot assume that when screen.keepAwake state |
76 // is changed from within a script, mojom::WakeLockService will receive an | 86 // is changed from within a script, mojom::WakeLockService will receive an |
77 // update request before ExecuteScript() returns. Therefore, some time slack | 87 // update request before ExecuteScript() returns. Therefore, some time slack |
78 // is needed to make sure that mojom::WakeLockService has received any | 88 // is needed to make sure that mojom::WakeLockService has received any |
79 // possible update requests before checking the resulting wake lock state. | 89 // possible update requests before checking the resulting wake lock state. |
80 base::PlatformThread::Sleep(TestTimeouts::tiny_timeout()); | 90 base::PlatformThread::Sleep(TestTimeouts::tiny_timeout()); |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 GetNestedFrame()->GetProcess(), | 377 GetNestedFrame()->GetProcess(), |
368 RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); | 378 RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); |
369 GetNestedFrame()->GetProcess()->Shutdown(0, false); | 379 GetNestedFrame()->GetProcess()->Shutdown(0, false); |
370 watcher.Wait(); | 380 watcher.Wait(); |
371 | 381 |
372 // Screen wake lock should be released. | 382 // Screen wake lock should be released. |
373 EXPECT_FALSE(HasWakeLock()); | 383 EXPECT_FALSE(HasWakeLock()); |
374 } | 384 } |
375 | 385 |
376 } // namespace content | 386 } // namespace content |
OLD | NEW |