Chromium Code Reviews| 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) | |
|
sky
2013/03/31 01:16:03
This isn't the right way to have a chromeos specif
sschmitz
2013/04/02 21:23:25
Removed ifdef Chrome OS
| |
| 6 | |
| 7 #include "ash/shell.h" | |
| 8 #include "base/bind.h" | |
| 9 #include "base/command_line.h" | |
| 10 #include "base/file_util.h" | |
| 11 #include "base/files/scoped_temp_dir.h" | |
| 12 #include "base/message_loop.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/common/chrome_notification_types.h" | |
| 17 #include "chrome/test/base/in_process_browser_test.h" | |
| 18 #include "content/public/test/test_utils.h" | |
| 19 #include "ui/aura/root_window.h" | |
| 20 #include "ui/message_center/message_center_switches.h" | |
| 21 | |
| 22 class ScreenshotTakerTest : public InProcessBrowserTest, | |
|
sky
2013/03/31 01:16:03
Why does this need to be a browser test instead of
sschmitz
2013/04/02 21:23:25
Changed to unit test
| |
| 23 public ScreenshotTakerObserver { | |
| 24 public: | |
| 25 ScreenshotTakerTest() | |
| 26 : running_(false), | |
| 27 screenshot_complete_(false), | |
| 28 screenshot_result_(ScreenshotTakerObserver::SCREENSHOT_SUCCESS) { | |
| 29 } | |
| 30 | |
| 31 virtual ~ScreenshotTakerTest() {} | |
| 32 | |
| 33 // Overridden from InProcessBrowserTest | |
| 34 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | |
| 35 command_line->AppendSwitch( | |
| 36 message_center::switches::kEnableRichNotifications); | |
| 37 } | |
| 38 | |
| 39 // Overridden from ScreenshotTakerObserver | |
| 40 virtual void OnScreenshotCompleted( | |
| 41 ScreenshotTakerObserver::Result screenshot_result, | |
| 42 const base::FilePath& screenshot_path) OVERRIDE { | |
| 43 screenshot_complete_ = true; | |
| 44 screenshot_result_ = screenshot_result; | |
| 45 screenshot_path_ = screenshot_path; | |
| 46 if (!running_) | |
| 47 return; | |
| 48 message_loop_runner_->Quit(); | |
| 49 running_ = false; | |
| 50 } | |
| 51 | |
| 52 protected: | |
| 53 void Wait() { | |
| 54 if (screenshot_complete_) | |
| 55 return; | |
| 56 running_ = true; | |
| 57 message_loop_runner_ = new content::MessageLoopRunner; | |
| 58 message_loop_runner_->Run(); | |
| 59 EXPECT_TRUE(screenshot_complete_); | |
| 60 } | |
| 61 | |
| 62 bool running_; | |
| 63 bool screenshot_complete_; | |
| 64 ScreenshotTakerObserver::Result screenshot_result_; | |
| 65 base::FilePath screenshot_path_; | |
| 66 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | |
| 67 | |
| 68 DISALLOW_COPY_AND_ASSIGN(ScreenshotTakerTest); | |
| 69 }; | |
| 70 | |
| 71 IN_PROC_BROWSER_TEST_F(ScreenshotTakerTest, TakeScreenshot) { | |
| 72 ScreenshotTaker screenshot_taker; | |
| 73 ScreenshotTaker::SetObserverForTest(this); | |
| 74 base::ScopedTempDir directory; | |
| 75 bool created_temp_dir = directory.CreateUniqueTempDir(); | |
| 76 ASSERT_TRUE(created_temp_dir); | |
| 77 screenshot_taker.SetScreenshotDirectoryForTest(directory.path()); | |
| 78 | |
| 79 EXPECT_TRUE(screenshot_taker.CanTakeScreenshot()); | |
| 80 | |
| 81 screenshot_taker.HandleTakePartialScreenshot( | |
| 82 ash::Shell::GetPrimaryRootWindow(), gfx::Rect(0,0,100,100)); | |
| 83 | |
| 84 EXPECT_FALSE(screenshot_taker.CanTakeScreenshot()); | |
| 85 | |
| 86 Wait(); | |
| 87 | |
| 88 EXPECT_TRUE(g_browser_process->notification_ui_manager()->DoesIdExist( | |
| 89 std::string("screenshot_001"))); | |
| 90 | |
| 91 EXPECT_EQ(ScreenshotTakerObserver::SCREENSHOT_SUCCESS, screenshot_result_); | |
| 92 | |
| 93 if (ScreenshotTakerObserver::SCREENSHOT_SUCCESS == screenshot_result_) | |
| 94 EXPECT_TRUE(file_util::PathExists(screenshot_path_)); | |
| 95 } | |
| 96 | |
| 97 #endif | |
| OLD | NEW |