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

Side by Side Diff: content/browser/wake_lock/wake_lock_browsertest.cc

Issue 2921823002: Rationalize WakeLock naming conventions (Closed)
Patch Set: rebase Created 3 years, 6 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
OLDNEW
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/message_loop/message_loop.h" 6 #include "base/message_loop/message_loop.h"
7 #include "base/test/test_timeouts.h" 7 #include "base/test/test_timeouts.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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 FrameTreeNode* GetNestedFrameNode() { 60 FrameTreeNode* GetNestedFrameNode() {
61 FrameTreeNode* root = GetWebContentsImpl()->GetFrameTree()->root(); 61 FrameTreeNode* root = GetWebContentsImpl()->GetFrameTree()->root();
62 CHECK_EQ(1U, root->child_count()); 62 CHECK_EQ(1U, root->child_count());
63 return root->child_at(0); 63 return root->child_at(0);
64 } 64 }
65 65
66 RenderFrameHost* GetNestedFrame() { 66 RenderFrameHost* GetNestedFrame() {
67 return GetNestedFrameNode()->current_frame_host(); 67 return GetNestedFrameNode()->current_frame_host();
68 } 68 }
69 69
70 device::mojom::WakeLockService* GetRendererWakeLock() { 70 device::mojom::WakeLock* GetRendererWakeLock() {
71 return GetWebContentsImpl()->GetRendererWakeLock(); 71 return GetWebContentsImpl()->GetRendererWakeLock();
72 } 72 }
73 73
74 bool HasWakeLock() { 74 bool HasWakeLock() {
75 bool has_wakelock = false; 75 bool has_wakelock = false;
76 base::RunLoop run_loop; 76 base::RunLoop run_loop;
77 77
78 GetRendererWakeLock()->HasWakeLockForTests( 78 GetRendererWakeLock()->HasWakeLockForTests(
79 base::Bind(&OnHasWakeLock, &has_wakelock)); 79 base::Bind(&OnHasWakeLock, &has_wakelock));
80 run_loop.Run(); 80 run_loop.Run();
81 return has_wakelock; 81 return has_wakelock;
82 } 82 }
83 83
84 void WaitForPossibleUpdate() { 84 void WaitForPossibleUpdate() {
85 // As Mojo channels have no common FIFO order in respect to each other and 85 // As Mojo channels have no common FIFO order in respect to each other and
86 // to the Chromium IPC, we cannot assume that when screen.keepAwake state 86 // to the Chromium IPC, we cannot assume that when screen.keepAwake state
87 // is changed from within a script, mojom::WakeLockService will receive an 87 // is changed from within a script, mojom::WakeLock will receive an
88 // update request before ExecuteScript() returns. Therefore, some time slack 88 // update request before ExecuteScript() returns. Therefore, some time slack
89 // is needed to make sure that mojom::WakeLockService has received any 89 // is needed to make sure that mojom::WakeLock has received any
90 // possible update requests before checking the resulting wake lock state. 90 // possible update requests before checking the resulting wake lock state.
91 base::PlatformThread::Sleep(TestTimeouts::tiny_timeout()); 91 base::PlatformThread::Sleep(TestTimeouts::tiny_timeout());
92 RunAllPendingInMessageLoop(); 92 RunAllPendingInMessageLoop();
93 } 93 }
94 94
95 void ScreenWakeLockInMainFrame() { 95 void ScreenWakeLockInMainFrame() {
96 EXPECT_TRUE(ExecuteScript(GetMainFrame(), "screen.keepAwake = true;")); 96 EXPECT_TRUE(ExecuteScript(GetMainFrame(), "screen.keepAwake = true;"));
97 WaitForPossibleUpdate(); 97 WaitForPossibleUpdate();
98 EXPECT_TRUE(HasWakeLock()); 98 EXPECT_TRUE(HasWakeLock());
99 } 99 }
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 GetNestedFrame()->GetProcess(), 378 GetNestedFrame()->GetProcess(),
379 RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); 379 RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT);
380 GetNestedFrame()->GetProcess()->Shutdown(0, false); 380 GetNestedFrame()->GetProcess()->Shutdown(0, false);
381 watcher.Wait(); 381 watcher.Wait();
382 382
383 // Screen wake lock should be released. 383 // Screen wake lock should be released.
384 EXPECT_FALSE(HasWakeLock()); 384 EXPECT_FALSE(HasWakeLock());
385 } 385 }
386 386
387 } // namespace content 387 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_impl.cc ('k') | content/browser/web_contents/web_contents_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698