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

Unified Diff: chrome/browser/ui/app_list/app_list_controller_browsertest.cc

Issue 23072036: Adds an integration test for uninstalling app list search results. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nit indenting Created 7 years, 4 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/app_list/app_list_controller_browsertest.cc
diff --git a/chrome/browser/ui/app_list/app_list_controller_browsertest.cc b/chrome/browser/ui/app_list/app_list_controller_browsertest.cc
index 05e0799dc0789d8763884ef986fc31b50a94c658..c6e018f7b042f9906f76422d86fdd5b5dea8bf82 100644
--- a/chrome/browser/ui/app_list/app_list_controller_browsertest.cc
+++ b/chrome/browser/ui/app_list/app_list_controller_browsertest.cc
@@ -6,8 +6,11 @@
#include "base/files/scoped_temp_dir.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
+#include "base/path_service.h"
#include "base/prefs/pref_service.h"
+#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/extensions/extension_browsertest.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/app_list/app_list_controller_delegate.h"
@@ -15,10 +18,18 @@
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/host_desktop.h"
+#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
+#include "ui/app_list/app_list_model.h"
+#include "ui/app_list/search_box_model.h"
+#include "ui/app_list/search_result.h"
+#include "ui/app_list/search_result_observer.h"
+#include "ui/base/models/list_model_observer.h"
+
+namespace {
// Browser Test for AppListController that runs on all platforms supporting
// app_list.
@@ -120,3 +131,107 @@ IN_PROC_BROWSER_TEST_F(ShowAppListBrowserTest, ShowAppListFlag) {
service->DismissAppList();
}
#endif // !defined(OS_CHROMEOS)
+
+// Browser Test for AppListController that observes search result changes.
+class AppListControllerSearchResultsBrowserTest
+ : public ExtensionBrowserTest,
+ public app_list::SearchResultObserver,
+ public ui::ListModelObserver {
+ public:
+ AppListControllerSearchResultsBrowserTest()
+ : observed_results_list_(NULL),
+ observed_result_(NULL),
+ item_uninstall_count_(0) {}
+
+ protected:
+ void Update() {
+ if (observed_result_) {
+ observed_result_->RemoveObserver(this);
+ observed_result_ = NULL;
+ }
+
+ for (size_t i = 0; i < observed_results_list_->item_count(); ++i) {
+ if (observed_results_list_->GetItemAt(i)->title() != item_to_observe_)
+ continue;
+
+ // Ensure there is at most one.
+ EXPECT_FALSE(observed_result_);
+ observed_result_ = observed_results_list_->GetItemAt(i);
+ }
+
+ if (observed_result_)
+ observed_result_->AddObserver(this);
+ }
+
+ // Overridden from SearchResultObserver:
+ virtual void OnIconChanged() OVERRIDE {}
+ virtual void OnActionsChanged() OVERRIDE {}
+ virtual void OnIsInstallingChanged() OVERRIDE {}
+ virtual void OnPercentDownloadedChanged() OVERRIDE {}
+ virtual void OnItemInstalled() OVERRIDE {}
+ virtual void OnItemUninstalled() OVERRIDE {
+ ++item_uninstall_count_;
+ EXPECT_TRUE(observed_result_);
+ }
+
+ // Overridden from ui::ListModelObserver:
+ virtual void ListItemsAdded(size_t start, size_t count) OVERRIDE { Update(); }
+ virtual void ListItemsRemoved(size_t start, size_t count) OVERRIDE {
+ Update();
+ }
+ virtual void ListItemMoved(size_t index, size_t target_index) OVERRIDE {}
+ virtual void ListItemsChanged(size_t start, size_t count) OVERRIDE {}
+
+ base::string16 item_to_observe_;
+ app_list::AppListModel::SearchResults* observed_results_list_;
+ app_list::SearchResult* observed_result_;
+ int item_uninstall_count_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(AppListControllerSearchResultsBrowserTest);
+};
+
+// Test showing search results, and uninstalling one of them while displayed.
+IN_PROC_BROWSER_TEST_F(AppListControllerSearchResultsBrowserTest,
+ UninstallSearchResult) {
+ base::FilePath test_extension_path;
+ ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_extension_path));
+ test_extension_path = test_extension_path.AppendASCII("extensions")
+ .AppendASCII("platform_apps")
+ .AppendASCII("minimal");
+ const extensions::Extension* extension =
+ InstallExtension(test_extension_path, 1);
+ EXPECT_TRUE(extension);
+ item_to_observe_ = ASCIIToUTF16(extension->name());
+
+ AppListService* service = AppListService::Get();
+ service->ShowForProfile(browser()->profile());
+ app_list::AppListModel* model = service->GetAppListModelForTesting();
+ model->SetSignedIn(true);
+ observed_results_list_ = model->results();
koz (OOO until 15th September) 2013/08/28 00:37:43 All the assigning to protected variables seems a l
tapted 2013/08/28 03:09:48 Done.
+ observed_results_list_->AddObserver(this);
+
+ // Ensure a search finds the extension.
+ EXPECT_FALSE(observed_result_);
+ model->search_box()->SetText(ASCIIToUTF16("minimal"));
+ EXPECT_TRUE(observed_result_);
+
+ // Ensure the UI is updated. This is via PostTask in views.
+ base::RunLoop().RunUntilIdle();
+
+ // Now uninstall and ensure this browser test observes it.
+ EXPECT_EQ(0, item_uninstall_count_);
+ UninstallExtension(extension->id());
+
+ // TODO(tapted): This should only see one notification. Currently it sees two.
+ // See http://crbug.com/277897 .
+ EXPECT_EQ(2, item_uninstall_count_);
+
+ // Results should not be immediately refreshed. When they are, the item should
+ // be removed from the model.
+ EXPECT_TRUE(observed_result_);
+ base::RunLoop().RunUntilIdle();
+ EXPECT_FALSE(observed_result_);
+}
+
+} // namespace

Powered by Google App Engine
This is Rietveld 408576698