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

Side by Side Diff: chrome/browser/ui/ash/screenshot_taker_browsertest.cc

Issue 13105002: Screenshot effect non-obvious (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: observer for test Created 7 years, 8 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
(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/files/scoped_temp_dir.h"
11 #include "base/message_loop.h"
12 #include "base/stringprintf.h"
13 #include "base/time.h"
James Cook 2013/03/29 20:00:32 Do you need "time.h"?
sschmitz 2013/03/29 21:02:35 Removed.
14 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/notifications/notification_ui_manager.h"
16 #include "chrome/browser/ui/ash/screenshot_taker.h"
17 #include "chrome/common/chrome_notification_types.h"
18 #include "chrome/test/base/in_process_browser_test.h"
19 #include "content/public/test/test_utils.h"
20 #include "ui/aura/root_window.h"
21 #include "ui/message_center/message_center_switches.h"
22
23 class ScreenshotTakerTest : public InProcessBrowserTest,
24 public ScreenshotTakerObserver {
25 public:
26 ScreenshotTakerTest()
27 : running_(false),
28 screenshot_complete_(false),
29 screenshot_result_(Screenshot::SCREENSHOT_SUCCESS) {
30 }
31
32 virtual ~ScreenshotTakerTest() {}
33
34 // Overridden from InProcessBrowserTest
35 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
36 command_line->AppendSwitch(
37 message_center::switches::kEnableRichNotifications);
38 }
39
40 // Overridden from ScreenshotTakerObserver
41 virtual void OnScreenshotCompleted(
42 Screenshot::Result screenshot_result,
43 const base::FilePath& screenshot_path) OVERRIDE {
44 screenshot_complete_ = true;
45 screenshot_result_ = screenshot_result;
46 screenshot_path_ = screenshot_path;
James Cook 2013/03/29 20:00:32 Do you need screenshot_path_?
sschmitz 2013/03/29 21:02:35 Added a test to verify that the file exists (if sc
47 if (!running_)
48 return;
49 message_loop_runner_->Quit();
50 running_ = false;
51 }
52
53 protected:
54 void Wait() {
55 if (screenshot_complete_)
56 return;
57 running_ = true;
58 message_loop_runner_ = new content::MessageLoopRunner;
59 message_loop_runner_->Run();
60 EXPECT_TRUE(screenshot_complete_);
61 }
62
63 void RunTest() {
James Cook 2013/03/29 20:00:32 We usually put most of this code in the IN_PROC_BR
sschmitz 2013/03/29 21:02:35 Done.
64 ScreenshotTaker screenshot_taker;
65 ScreenshotTaker::SetObserverForTest(this);
66 base::ScopedTempDir directory;
67 bool created_temp_dir = directory.CreateUniqueTempDir();
68 ASSERT_TRUE(created_temp_dir);
69 screenshot_taker.SetScreenshotDirectoryForTest(directory.path());
70
71 EXPECT_TRUE(screenshot_taker.CanTakeScreenshot());
72
73 screenshot_taker.HandleTakePartialScreenshot(
74 ash::Shell::GetPrimaryRootWindow(), gfx::Rect(0,0,100,100));
75
76 EXPECT_FALSE(screenshot_taker.CanTakeScreenshot());
77
78 Wait();
79
80 EXPECT_TRUE(g_browser_process->notification_ui_manager()->DoesIdExist(
81 base::StringPrintf("screenshot_%3.3d", 1)));
James Cook 2013/03/29 20:00:32 Do you need StringPrintf here? Why not just provid
sschmitz 2013/03/29 21:02:35 Done.
82
83 EXPECT_EQ(Screenshot::SCREENSHOT_SUCCESS, screenshot_result_);
84 }
85
86 bool running_;
87 bool screenshot_complete_;
88 Screenshot::Result screenshot_result_;
89 base::FilePath screenshot_path_;
90 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
91
92 DISALLOW_COPY_AND_ASSIGN(ScreenshotTakerTest);
93 };
94
95 IN_PROC_BROWSER_TEST_F(ScreenshotTakerTest, TakeScreenshot) {
96 RunTest();
97 }
98
99 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698