OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #if defined(OS_CHROMEOS) | |
6 | |
7 #include "ash/shell.h" | |
8 #include "base/bind.h" | |
9 #include "base/command_line.h" | |
10 #include "base/message_loop.h" | |
11 #include "base/stringprintf.h" | |
12 #include "base/time.h" | |
13 #include "chrome/browser/browser_process.h" | |
14 #include "chrome/browser/notifications/notification_ui_manager.h" | |
15 #include "chrome/browser/ui/ash/screenshot_taker.h" | |
16 #include "chrome/test/base/in_process_browser_test.h" | |
17 #include "ui/aura/root_window.h" | |
18 #include "ui/message_center/message_center_switches.h" | |
19 | |
20 class ScreenshotTakerTest : public InProcessBrowserTest { | |
21 public: | |
22 ScreenshotTakerTest() {} | |
23 virtual ~ScreenshotTakerTest() {} | |
24 | |
25 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | |
26 command_line->AppendSwitch( | |
27 message_center::switches::kEnableRichNotifications); | |
28 } | |
29 | |
30 private: | |
31 DISALLOW_COPY_AND_ASSIGN(ScreenshotTakerTest); | |
32 }; | |
33 | |
34 namespace { | |
35 // Saving screenshots to file happens on a blocking pool thread. When | |
36 // completed, a notification is added (from the browser ui thread). | |
37 // We repeatedly check for this notification to be present or exit | |
James Cook
2013/03/28 19:49:36
You can't write browser tests in Chrome this way (
sschmitz
2013/03/28 23:52:41
Thanks for the info... done.
| |
38 // with a time-out error. On my Linux desktop success is reached typically | |
39 // on the 2nd or 3rd invocation of check_for_notification within < ~20 msec. | |
40 void check_for_notification(std::string notification_id, | |
41 base::TimeDelta start_time) { | |
42 if (g_browser_process->notification_ui_manager()->DoesIdExist( | |
43 notification_id)) { | |
44 return; // success | |
45 } | |
46 base::TimeDelta delta_time = base::TimeDelta::FromInternalValue( | |
47 base::TimeTicks::Now().ToInternalValue()) - start_time; | |
48 double limit_msec = 500.0; | |
49 EXPECT_LT(delta_time.InMillisecondsF(), limit_msec); | |
50 if (delta_time.InMillisecondsF() < limit_msec) { | |
51 MessageLoop::current()->PostTask( | |
52 FROM_HERE, | |
53 base::Bind(&check_for_notification, notification_id, start_time)); | |
54 } | |
55 } | |
56 } | |
57 | |
58 IN_PROC_BROWSER_TEST_F(ScreenshotTakerTest, TakeScreenshot) { | |
59 ScreenshotTaker screenshot_taker; | |
60 EXPECT_TRUE(screenshot_taker.CanTakeScreenshot()); | |
61 | |
62 screenshot_taker.HandleTakePartialScreenshot( | |
63 ash::Shell::GetPrimaryRootWindow(), gfx::Rect(0,0,100,100)); | |
64 EXPECT_FALSE(screenshot_taker.CanTakeScreenshot()); | |
65 | |
66 std::string notification_id = base::StringPrintf("screenshot_%3.3d", 1); | |
67 base::TimeDelta start_time = base::TimeDelta::FromInternalValue( | |
68 base::TimeTicks::Now().ToInternalValue()); | |
69 MessageLoop::current()->PostTask( | |
70 FROM_HERE, | |
71 base::Bind(&check_for_notification, notification_id, start_time)); | |
72 | |
73 MessageLoop::current()->RunUntilIdle(); | |
74 } | |
75 | |
76 #endif | |
OLD | NEW |