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 #include "ash/shell.h" | |
6 #include "ash/test/ash_test_base.h" | |
7 #include "base/bind.h" | |
8 #include "base/command_line.h" | |
9 #include "base/file_util.h" | |
10 #include "base/files/scoped_temp_dir.h" | |
11 #include "base/message_loop.h" | |
12 #include "chrome/browser/browser_process.h" | |
13 #include "chrome/browser/notifications/notification_ui_manager.h" | |
14 #include "chrome/browser/ui/ash/screenshot_taker.h" | |
15 #include "chrome/test/base/in_process_browser_test.h" | |
16 #include "chrome/test/base/scoped_testing_local_state.h" | |
17 #include "chrome/test/base/testing_browser_process.h" | |
18 #include "chrome/test/base/testing_profile.h" | |
19 #include "content/public/browser/browser_thread.h" | |
20 #include "content/public/test/test_browser_thread.h" | |
21 #include "content/public/test/test_utils.h" | |
22 #include "ui/aura/root_window.h" | |
23 #include "ui/message_center/message_center_switches.h" | |
24 | |
25 namespace ash { | |
26 namespace test { | |
27 | |
28 class ScreenshotTakerTest : public AshTestBase, | |
29 public ScreenshotTakerObserver { | |
30 public: | |
31 ScreenshotTakerTest() | |
32 : local_state_(TestingBrowserProcess::GetGlobal()), | |
33 running_(false), | |
34 screenshot_complete_(false), | |
35 screenshot_result_(ScreenshotTakerObserver::SCREENSHOT_SUCCESS) { | |
36 MessageLoopForUI* ui_loop = message_loop(); | |
37 ui_thread_.reset( | |
38 new content::TestBrowserThread(content::BrowserThread::UI, ui_loop)); | |
39 } | |
40 | |
41 virtual ~ScreenshotTakerTest() { | |
42 screenshot_taker_->RemoveObserver(this); | |
James Cook
2013/04/02 22:47:18
Things you built in SetUp() should be cleaned up i
sschmitz
2013/04/03 17:57:40
Reorganized so overridden SetUp and TearDown not n
| |
43 screenshot_taker_.reset(); | |
44 profile_.reset(); | |
45 ui_thread_.reset(); | |
46 } | |
47 | |
48 // Overridden from AshTestBase: | |
49 virtual void SetUp() { | |
50 CommandLine::ForCurrentProcess()->AppendSwitch( | |
51 message_center::switches::kEnableRichNotifications); | |
52 AshTestBase::SetUp(); | |
53 profile_.reset(new TestingProfile()); | |
James Cook
2013/04/02 22:47:18
Can profile_, screenshot_taker_ and directory be m
sschmitz
2013/04/03 17:57:40
Good Point. done.
| |
54 base::ScopedTempDir directory; | |
James Cook
2013/04/02 22:47:18
I think this directory will be deleted when SetUp(
sschmitz
2013/04/03 17:57:40
Of course, I can't believe I did this. Reorganized
| |
55 ASSERT_TRUE(directory.CreateUniqueTempDir()); | |
56 screenshot_taker_.reset(new ScreenshotTaker(profile_.get())); | |
57 screenshot_taker_->AddObserver(this); | |
58 screenshot_taker_->OverrideScreenshotDirectory(directory.path()); | |
59 screenshot_taker_->OverrideScreenshotBasename("Screenshot"); | |
60 } | |
61 | |
62 // Overridden from ScreenshotTakerObserver | |
63 virtual void OnScreenshotCompleted( | |
64 ScreenshotTakerObserver::Result screenshot_result, | |
65 const base::FilePath& screenshot_path) OVERRIDE { | |
66 screenshot_complete_ = true; | |
67 screenshot_result_ = screenshot_result; | |
68 screenshot_path_ = screenshot_path; | |
69 if (!running_) | |
70 return; | |
71 message_loop_runner_->Quit(); | |
72 running_ = false; | |
73 } | |
74 | |
75 protected: | |
76 void Wait() { | |
77 if (screenshot_complete_) | |
78 return; | |
79 running_ = true; | |
80 message_loop_runner_ = new content::MessageLoopRunner; | |
81 message_loop_runner_->Run(); | |
82 EXPECT_TRUE(screenshot_complete_); | |
83 } | |
84 | |
85 ScopedTestingLocalState local_state_; | |
86 scoped_ptr<content::TestBrowserThread> ui_thread_; | |
87 scoped_ptr<TestingProfile> profile_; | |
88 scoped_ptr<ScreenshotTaker> screenshot_taker_; | |
89 base::ScopedTempDir temp_dir_; | |
James Cook
2013/04/02 22:47:18
Is this used?
sschmitz
2013/04/03 17:57:40
Nope, removed.
| |
90 bool running_; | |
91 bool screenshot_complete_; | |
92 ScreenshotTakerObserver::Result screenshot_result_; | |
93 base::FilePath screenshot_path_; | |
94 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | |
95 | |
96 DISALLOW_COPY_AND_ASSIGN(ScreenshotTakerTest); | |
97 }; | |
98 | |
99 TEST_F(ScreenshotTakerTest, TakeScreenshot) { | |
100 EXPECT_TRUE(screenshot_taker_->CanTakeScreenshot()); | |
101 | |
102 screenshot_taker_->HandleTakePartialScreenshot( | |
103 ash::Shell::GetPrimaryRootWindow(), gfx::Rect(0,0,100,100)); | |
104 | |
105 EXPECT_FALSE(screenshot_taker_->CanTakeScreenshot()); | |
106 | |
107 Wait(); | |
108 | |
109 EXPECT_TRUE(g_browser_process->notification_ui_manager()->DoesIdExist( | |
110 std::string("screenshot_001"))); | |
111 | |
112 EXPECT_EQ(ScreenshotTakerObserver::SCREENSHOT_SUCCESS, screenshot_result_); | |
113 | |
114 if (ScreenshotTakerObserver::SCREENSHOT_SUCCESS == screenshot_result_) | |
115 EXPECT_TRUE(file_util::PathExists(screenshot_path_)); | |
116 } | |
117 | |
118 } // namespace test | |
119 } // namespace ash | |
OLD | NEW |