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

Unified Diff: chrome/browser/ui/views/apps/app_info_dialog/app_info_dialog_views_unittest.cc

Issue 1175783003: Split out Ash dependency in app info dialog unittests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ViewEventTestBase will not play nice Created 5 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/apps/app_info_dialog/app_info_dialog_views_unittest.cc
diff --git a/chrome/browser/ui/views/apps/app_info_dialog/app_info_dialog_views_unittest.cc b/chrome/browser/ui/views/apps/app_info_dialog/app_info_dialog_views_unittest.cc
index 28d8a53e2c184b2a99155554da7bb5bfd0f9654b..8f79ac323e2e11efe2003b345815c023a4f5891d 100644
--- a/chrome/browser/ui/views/apps/app_info_dialog/app_info_dialog_views_unittest.cc
+++ b/chrome/browser/ui/views/apps/app_info_dialog/app_info_dialog_views_unittest.cc
@@ -4,27 +4,18 @@
#include "chrome/browser/ui/views/apps/app_info_dialog/app_info_dialog_views.h"
-#include "ash/test/ash_test_base.h"
-#include "base/command_line.h"
#include "base/memory/scoped_ptr.h"
+#include "base/run_loop.h"
#include "chrome/browser/extensions/extension_service.h"
-#include "chrome/browser/extensions/test_extension_system.h"
-#include "chrome/browser/ui/views/apps/app_info_dialog/app_info_footer_panel.h"
+#include "chrome/browser/extensions/test_extension_environment.h"
#include "chrome/test/base/testing_profile.h"
-#include "extensions/browser/extension_prefs.h"
-#include "extensions/common/extension_builder.h"
+#include "extensions/browser/extension_system.h"
#include "testing/gtest/include/gtest/gtest.h"
-#include "ui/views/controls/button/label_button.h"
+#include "ui/views/test/scoped_views_test_helper.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_observer.h"
#include "ui/views/window/dialog_delegate.h"
-#if defined(OS_CHROMEOS)
-#include "chrome/browser/chromeos/login/users/scoped_test_user_manager.h"
-#include "chrome/browser/chromeos/settings/cros_settings.h"
-#include "chrome/browser/chromeos/settings/device_settings_service.h"
-#endif
-
namespace {
const char kTestExtensionId[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
@@ -32,43 +23,27 @@ const char kTestOtherExtensionId[] = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb";
} // namespace
-class AppInfoDialogViewsTest : public ash::test::AshTestBase,
+class AppInfoDialogViewsTest : public testing::Test,
public views::WidgetObserver {
public:
- AppInfoDialogViewsTest()
- : widget_(NULL),
- widget_destroyed_(false),
- command_line_(base::CommandLine::NO_PROGRAM) {}
- ~AppInfoDialogViewsTest() override {}
+ AppInfoDialogViewsTest() {}
// Overridden from testing::Test:
void SetUp() override {
- ash::test::AshTestBase::SetUp();
-
widget_ = views::DialogDelegate::CreateDialogWidget(
- new views::DialogDelegateView(), CurrentContext(), NULL);
+ new views::DialogDelegateView(), views_test_helper_.GetContext(), NULL);
widget_->AddObserver(this);
- profile_.reset(new TestingProfile());
- CreateExtensionSystemForProfile(profile_.get());
-
- app_ = extensions::ExtensionBuilder()
- .SetManifest(ValidAppManifest())
- .SetID(kTestExtensionId)
- .Build();
- InstallApp(profile_.get(), app_.get());
-
dialog_ = new AppInfoDialog(
- widget_->GetNativeWindow(), profile_.get(), app_.get());
+ widget_->GetNativeWindow(), extension_environment_.profile(),
+ extension_environment_.MakePackagedApp(kTestExtensionId, true).get());
widget_->GetContentsView()->AddChildView(dialog_);
}
void TearDown() override {
if (!widget_destroyed_)
widget_->CloseNow();
- widget_ = NULL;
- profile_.reset();
- ash::test::AshTestBase::TearDown();
+ EXPECT_TRUE(widget_destroyed_);
}
protected:
@@ -79,66 +54,20 @@ class AppInfoDialogViewsTest : public ash::test::AshTestBase,
widget_ = NULL;
}
- void CreateExtensionSystemForProfile(Profile* profile) {
- extensions::TestExtensionSystem* test_extension_system =
- static_cast<extensions::TestExtensionSystem*>(
- extensions::ExtensionSystem::Get(profile));
- test_extension_system->CreateExtensionService(
- &command_line_,
- base::FilePath() /* install_directory */,
- false /* autoupdate_enabled*/);
- }
-
- void InstallApp(Profile* profile, const extensions::Extension* app) {
- extensions::ExtensionSystem::Get(profile)
- ->extension_service()
- ->AddExtension(app);
- }
-
void UninstallApp(const std::string& app_id) {
- extensions::ExtensionSystem::Get(profile_.get())
+ extensions::ExtensionSystem::Get(extension_environment_.profile())
->extension_service()
->UninstallExtension(
- app_id,
- extensions::UninstallReason::UNINSTALL_REASON_FOR_TESTING,
- base::Closure(),
- NULL);
- }
-
- // TODO(sashab): Move this into extension_test_util.h and update the calls
- // from AppInfoPermissionsPanelTest as well.
- scoped_ptr<base::DictionaryValue> ValidAppManifest() {
- return extensions::DictionaryBuilder()
- .Set("name", "Test App Name")
- .Set("version", "2.0")
- .Set("manifest_version", 2)
- .Set("app",
- extensions::DictionaryBuilder().Set(
- "background",
- extensions::DictionaryBuilder().Set(
- "scripts",
- extensions::ListBuilder().Append("background.js"))))
- .Build();
+ app_id, extensions::UninstallReason::UNINSTALL_REASON_FOR_TESTING,
+ base::Closure(), NULL);
}
protected:
- scoped_ptr<TestingProfile> profile_;
- views::Widget* widget_;
- bool widget_destroyed_;
- AppInfoDialog* dialog_; // Owned by widget_ through views heirarchy.
-
- private:
- base::CommandLine command_line_;
-
- scoped_refptr<const extensions::Extension> app_;
-
-#if defined OS_CHROMEOS
- // Set up a user manager so these tests will run on ChromeOS. These member
- // variables need to be initialized in this order.
- chromeos::ScopedTestDeviceSettingsService test_device_settings_service_;
- chromeos::ScopedTestCrosSettings test_cros_settings_;
- chromeos::ScopedTestUserManager test_user_manager_;
-#endif
+ views::Widget* widget_ = nullptr;
+ bool widget_destroyed_ = false;
+ AppInfoDialog* dialog_ = nullptr; // Owned by |widget_|'s views hierarchy.
+ extensions::TestExtensionEnvironment extension_environment_;
+ views::ScopedViewsTestHelper views_test_helper_;
DISALLOW_COPY_AND_ASSIGN(AppInfoDialogViewsTest);
};
@@ -148,25 +77,18 @@ TEST_F(AppInfoDialogViewsTest, UninstallingAppClosesDialog) {
EXPECT_FALSE(widget_->IsClosed());
EXPECT_FALSE(widget_destroyed_);
UninstallApp(kTestExtensionId);
- RunAllPendingInMessageLoop();
+ base::RunLoop().RunUntilIdle();
EXPECT_TRUE(widget_destroyed_);
}
// Tests that the dialog does not close when a different app is uninstalled.
TEST_F(AppInfoDialogViewsTest, UninstallingOtherAppDoesNotCloseDialog) {
- scoped_refptr<const extensions::Extension> other_app =
- extensions::ExtensionBuilder()
- .SetManifest(ValidAppManifest())
- .SetID(kTestOtherExtensionId)
- .Build();
- extensions::ExtensionSystem::Get(profile_.get())
- ->extension_service()
- ->AddExtension(other_app.get());
+ extension_environment_.MakePackagedApp(kTestOtherExtensionId, true);
EXPECT_FALSE(widget_->IsClosed());
EXPECT_FALSE(widget_destroyed_);
UninstallApp(kTestOtherExtensionId);
- RunAllPendingInMessageLoop();
+ base::RunLoop().RunUntilIdle();
EXPECT_FALSE(widget_destroyed_);
}
@@ -174,50 +96,25 @@ TEST_F(AppInfoDialogViewsTest, UninstallingOtherAppDoesNotCloseDialog) {
TEST_F(AppInfoDialogViewsTest, DestroyedProfileClosesDialog) {
EXPECT_FALSE(widget_->IsClosed());
EXPECT_FALSE(widget_destroyed_);
- profile_.reset();
- RunAllPendingInMessageLoop();
+ extension_environment_.DeleteProfile();
+ base::RunLoop().RunUntilIdle();
EXPECT_TRUE(widget_destroyed_);
}
// Tests that the dialog does not close when a different profile is destroyed.
TEST_F(AppInfoDialogViewsTest, DestroyedOtherProfileDoesNotCloseDialog) {
- scoped_ptr<TestingProfile> other_profile;
- other_profile.reset(new TestingProfile());
- CreateExtensionSystemForProfile(other_profile.get());
+ scoped_ptr<TestingProfile> other_profile(new TestingProfile);
+ extension_environment_.CreateExtensionServiceForProfile(other_profile.get());
+
scoped_refptr<const extensions::Extension> other_app =
- extensions::ExtensionBuilder()
- .SetManifest(ValidAppManifest())
- .SetID(kTestOtherExtensionId)
- .Build();
- InstallApp(other_profile.get(), other_app.get());
+ extension_environment_.MakePackagedApp(kTestOtherExtensionId, false);
+ extensions::ExtensionSystem::Get(other_profile.get())
+ ->extension_service()
+ ->AddExtension(other_app.get());
EXPECT_FALSE(widget_->IsClosed());
EXPECT_FALSE(widget_destroyed_);
other_profile.reset();
- RunAllPendingInMessageLoop();
+ base::RunLoop().RunUntilIdle();
EXPECT_FALSE(widget_destroyed_);
}
-
-// Tests that the pin/unpin button is focused after unpinning/pinning. This is
-// to verify regression in crbug.com/428704 is fixed.
-TEST_F(AppInfoDialogViewsTest, PinButtonsAreFocusedAfterPinUnpin) {
- AppInfoFooterPanel* dialog_footer =
- static_cast<AppInfoFooterPanel*>(dialog_->dialog_footer_);
- views::View* pin_button = dialog_footer->pin_to_shelf_button_;
- views::View* unpin_button = dialog_footer->unpin_from_shelf_button_;
-
- pin_button->RequestFocus();
- EXPECT_TRUE(pin_button->visible());
- EXPECT_FALSE(unpin_button->visible());
- EXPECT_TRUE(pin_button->HasFocus());
-
- dialog_footer->SetPinnedToShelf(true);
- EXPECT_FALSE(pin_button->visible());
- EXPECT_TRUE(unpin_button->visible());
- EXPECT_TRUE(unpin_button->HasFocus());
-
- dialog_footer->SetPinnedToShelf(false);
- EXPECT_TRUE(pin_button->visible());
- EXPECT_FALSE(unpin_button->visible());
- EXPECT_TRUE(pin_button->HasFocus());
-}

Powered by Google App Engine
This is Rietveld 408576698