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

Unified Diff: chrome/browser/ui/ash/chrome_screenshot_taker_unittest.cc

Issue 706013004: Move non-browser specific ScreenshotTaker code to ui/snapshot. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix missing comma. Created 6 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/ash/chrome_screenshot_taker_unittest.cc
diff --git a/chrome/browser/ui/ash/screenshot_taker_unittest.cc b/chrome/browser/ui/ash/chrome_screenshot_taker_unittest.cc
similarity index 57%
rename from chrome/browser/ui/ash/screenshot_taker_unittest.cc
rename to chrome/browser/ui/ash/chrome_screenshot_taker_unittest.cc
index 103f6b80197782bfc2a241d5523173d8bee4d16d..65a818205e75e7e323a49e231be904795b167c80 100644
--- a/chrome/browser/ui/ash/screenshot_taker_unittest.cc
+++ b/chrome/browser/ui/ash/chrome_screenshot_taker_unittest.cc
@@ -2,8 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/ui/ash/screenshot_taker.h"
+#include "chrome/browser/ui/ash/chrome_screenshot_taker.h"
+#include "ash/accelerators/accelerator_controller.h"
#include "ash/shell.h"
#include "ash/test/ash_test_base.h"
#include "base/bind.h"
@@ -13,12 +14,14 @@
#include "base/message_loop/message_loop.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/notifications/notification_ui_manager.h"
+#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/base/testing_profile_manager.h"
#include "content/public/test/test_utils.h"
#include "ui/aura/window_event_dispatcher.h"
+#include "ui/snapshot/screenshot_taker.h"
#if defined(OS_CHROMEOS)
#include "chromeos/login/login_state.h"
@@ -27,23 +30,54 @@
namespace ash {
namespace test {
-class ScreenshotTakerTest : public AshTestBase,
- public ScreenshotTakerObserver {
+namespace {
+
+class TestChromeScreenshotTaker : public ChromeScreenshotTaker {
+ public:
+ TestChromeScreenshotTaker()
+ : profile_manager_(
+ new TestingProfileManager(TestingBrowserProcess::GetGlobal())) {
+ CHECK(profile_manager_->SetUp());
+ profile_ = profile_manager_->CreateTestingProfile("test_profile");
+ }
+ ~TestChromeScreenshotTaker() override {}
+
+ TestingProfile* profile() { return profile_; }
+
+ protected:
+ Profile* GetProfile() override { return profile(); }
+
+ private:
+ scoped_ptr<TestingProfileManager> profile_manager_;
+ TestingProfile* profile_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestChromeScreenshotTaker);
+};
+
+} // namespace
+
+class ChromeScreenshotTakerTest : public AshTestBase,
+ public ui::ScreenshotTakerObserver {
public:
- ScreenshotTakerTest()
+ ChromeScreenshotTakerTest()
: running_(false),
screenshot_complete_(false),
- screenshot_result_(ScreenshotTakerObserver::SCREENSHOT_SUCCESS) {
- }
+ screenshot_result_(ScreenshotTakerObserver::SCREENSHOT_SUCCESS) {}
- void SetUp() override { AshTestBase::SetUp(); }
+ void SetUp() override {
+ AshTestBase::SetUp();
+ chrome_screenshot_taker_.reset(new TestChromeScreenshotTaker);
+ screenshot_taker()->AddObserver(this);
+ }
void TearDown() override {
RunAllPendingInMessageLoop();
+ screenshot_taker()->RemoveObserver(this);
+ chrome_screenshot_taker_.reset();
AshTestBase::TearDown();
}
- // Overridden from ScreenshotTakerObserver
+ // Overridden from ui::ScreenshotTakerObserver
void OnScreenshotCompleted(ScreenshotTakerObserver::Result screenshot_result,
const base::FilePath& screenshot_path) override {
screenshot_complete_ = true;
@@ -56,24 +90,6 @@ class ScreenshotTakerTest : public AshTestBase,
}
protected:
- // ScreenshotTakerTest is a friend of ScreenshotTaker and therefore
- // allowed to set the directory, basename and profile.
- void SetScreenshotDirectoryForTest(
- ScreenshotTaker* screenshot_taker,
- const base::FilePath& screenshot_directory) {
- screenshot_taker->SetScreenshotDirectoryForTest(screenshot_directory);
- }
- void SetScreenshotBasenameForTest(
- ScreenshotTaker* screenshot_taker,
- const std::string& screenshot_basename) {
- screenshot_taker->SetScreenshotBasenameForTest(screenshot_basename);
- }
- void SetScreenshotProfileForTest(
- ScreenshotTaker* screenshot_taker,
- Profile* profile) {
- screenshot_taker->SetScreenshotProfileForTest(profile);
- }
-
void Wait() {
if (screenshot_complete_)
return;
@@ -83,42 +99,41 @@ class ScreenshotTakerTest : public AshTestBase,
EXPECT_TRUE(screenshot_complete_);
}
+ TestChromeScreenshotTaker* chrome_screenshot_taker() {
+ return chrome_screenshot_taker_.get();
+ }
+
+ ui::ScreenshotTaker* screenshot_taker() {
+ return chrome_screenshot_taker_->screenshot_taker_.get();
+ }
+
bool running_;
bool screenshot_complete_;
ScreenshotTakerObserver::Result screenshot_result_;
+ scoped_ptr<TestChromeScreenshotTaker> chrome_screenshot_taker_;
base::FilePath screenshot_path_;
scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
private:
- DISALLOW_COPY_AND_ASSIGN(ScreenshotTakerTest);
+ DISALLOW_COPY_AND_ASSIGN(ChromeScreenshotTakerTest);
};
-TEST_F(ScreenshotTakerTest, TakeScreenshot) {
+TEST_F(ChromeScreenshotTakerTest, TakeScreenshot) {
#if defined(OS_CHROMEOS)
// Note that within the test framework the LoginState object will always
// claim that the user did log in.
ASSERT_FALSE(chromeos::LoginState::IsInitialized());
chromeos::LoginState::Initialize();
#endif
- scoped_ptr<TestingProfileManager> profile_manager(
- new TestingProfileManager(TestingBrowserProcess::GetGlobal()));
- ASSERT_TRUE(profile_manager->SetUp());
- TestingProfile* profile =
- profile_manager->CreateTestingProfile("test_profile");
- ScreenshotTaker screenshot_taker;
- screenshot_taker.AddObserver(this);
base::ScopedTempDir directory;
ASSERT_TRUE(directory.CreateUniqueTempDir());
- SetScreenshotDirectoryForTest(&screenshot_taker, directory.path());
- SetScreenshotBasenameForTest(&screenshot_taker, "Screenshot");
- SetScreenshotProfileForTest(&screenshot_taker, profile);
-
- EXPECT_TRUE(screenshot_taker.CanTakeScreenshot());
+ EXPECT_TRUE(chrome_screenshot_taker()->CanTakeScreenshot());
- screenshot_taker.HandleTakePartialScreenshot(
- Shell::GetPrimaryRootWindow(), gfx::Rect(0, 0, 100, 100));
+ screenshot_taker()->TakeScreenshot(
+ Shell::GetPrimaryRootWindow(), gfx::Rect(0, 0, 100, 100),
+ directory.path().AppendASCII("Screenshot.png"));
- EXPECT_FALSE(screenshot_taker.CanTakeScreenshot());
+ EXPECT_FALSE(screenshot_taker()->CanTakeScreenshot());
Wait();
@@ -126,7 +141,8 @@ TEST_F(ScreenshotTakerTest, TakeScreenshot) {
// Screenshot notifications on Windows not yet turned on.
EXPECT_TRUE(g_browser_process->notification_ui_manager()->FindById(
std::string("screenshot"),
- NotificationUIManager::GetProfileID(profile)) != NULL);
+ NotificationUIManager::GetProfileID(
+ chrome_screenshot_taker()->profile())) != NULL);
g_browser_process->notification_ui_manager()->CancelAll();
#endif

Powered by Google App Engine
This is Rietveld 408576698