Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / ui / app_list / app_list_controller_browsertest.cc
blob2d88b3fda172711baa036b7ab1de5ef23c98fa41
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.
5 #include "base/command_line.h"
6 #include "base/path_service.h"
7 #include "base/run_loop.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/extensions/extension_browsertest.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h"
12 #include "chrome/browser/ui/app_list/app_list_service.h"
13 #include "chrome/browser/ui/app_list/test/chrome_app_list_test_support.h"
14 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/browser_finder.h"
16 #include "chrome/browser/ui/host_desktop.h"
17 #include "chrome/common/chrome_paths.h"
18 #include "chrome/common/chrome_switches.h"
19 #include "chrome/test/base/in_process_browser_test.h"
20 #include "chrome/test/base/testing_profile.h"
21 #include "ui/app_list/app_list_model.h"
22 #include "ui/app_list/app_list_switches.h"
23 #include "ui/app_list/search_box_model.h"
24 #include "ui/app_list/search_result.h"
25 #include "ui/app_list/search_result_observer.h"
26 #include "ui/base/models/list_model_observer.h"
28 #if defined(OS_CHROMEOS)
29 #include "chromeos/chromeos_switches.h"
30 #include "chromeos/login/user_names.h"
31 #endif // defined(OS_CHROMEOS)
33 // Browser Test for AppListController that runs on all platforms supporting
34 // app_list.
35 typedef InProcessBrowserTest AppListControllerBrowserTest;
37 // Test the CreateNewWindow function of the controller delegate.
38 IN_PROC_BROWSER_TEST_F(AppListControllerBrowserTest, CreateNewWindow) {
39 const chrome::HostDesktopType desktop = chrome::GetActiveDesktop();
40 AppListService* service = test::GetAppListService();
41 AppListControllerDelegate* controller(service->GetControllerDelegate());
42 ASSERT_TRUE(controller);
44 EXPECT_EQ(1U, chrome::GetBrowserCount(browser()->profile(), desktop));
45 EXPECT_EQ(0U, chrome::GetBrowserCount(
46 browser()->profile()->GetOffTheRecordProfile(), desktop));
48 controller->CreateNewWindow(browser()->profile(), false);
49 EXPECT_EQ(2U, chrome::GetBrowserCount(browser()->profile(), desktop));
51 controller->CreateNewWindow(browser()->profile(), true);
52 EXPECT_EQ(1U, chrome::GetBrowserCount(
53 browser()->profile()->GetOffTheRecordProfile(), desktop));
56 // Browser Test for AppListController that observes search result changes.
57 class AppListControllerSearchResultsBrowserTest
58 : public ExtensionBrowserTest,
59 public app_list::SearchResultObserver,
60 public ui::ListModelObserver {
61 public:
62 AppListControllerSearchResultsBrowserTest()
63 : observed_result_(NULL),
64 observed_results_list_(NULL) {}
66 void WatchResultsLookingForItem(
67 app_list::AppListModel::SearchResults* search_results,
68 const std::string& extension_name) {
69 EXPECT_FALSE(observed_results_list_);
70 observed_results_list_ = search_results;
71 observed_results_list_->AddObserver(this);
72 item_to_observe_ = base::ASCIIToUTF16(extension_name);
75 void StopWatchingResults() {
76 EXPECT_TRUE(observed_results_list_);
77 observed_results_list_->RemoveObserver(this);
80 protected:
81 void AttemptToLocateItem() {
82 if (observed_result_) {
83 observed_result_->RemoveObserver(this);
84 observed_result_ = NULL;
87 for (size_t i = 0; i < observed_results_list_->item_count(); ++i) {
88 if (observed_results_list_->GetItemAt(i)->title() != item_to_observe_)
89 continue;
91 // Ensure there is at most one.
92 EXPECT_FALSE(observed_result_);
93 observed_result_ = observed_results_list_->GetItemAt(i);
96 if (observed_result_)
97 observed_result_->AddObserver(this);
100 // Overridden from SearchResultObserver:
101 void OnIconChanged() override {}
102 void OnActionsChanged() override {}
103 void OnIsInstallingChanged() override {}
104 void OnPercentDownloadedChanged() override {}
105 void OnItemInstalled() override {}
107 // Overridden from ui::ListModelObserver:
108 void ListItemsAdded(size_t start, size_t count) override {
109 AttemptToLocateItem();
111 void ListItemsRemoved(size_t start, size_t count) override {
112 AttemptToLocateItem();
114 void ListItemMoved(size_t index, size_t target_index) override {}
115 void ListItemsChanged(size_t start, size_t count) override {}
117 app_list::SearchResult* observed_result_;
119 private:
120 base::string16 item_to_observe_;
121 app_list::AppListModel::SearchResults* observed_results_list_;
123 DISALLOW_COPY_AND_ASSIGN(AppListControllerSearchResultsBrowserTest);
127 // Flaky on Mac. https://crbug.com/415264
128 #if defined(OS_MACOSX)
129 #define MAYBE_UninstallSearchResult DISABLED_UninstallSearchResult
130 #else
131 #define MAYBE_UninstallSearchResult UninstallSearchResult
132 #endif
133 // Test showing search results, and uninstalling one of them while displayed.
134 IN_PROC_BROWSER_TEST_F(AppListControllerSearchResultsBrowserTest,
135 MAYBE_UninstallSearchResult) {
136 base::FilePath test_extension_path;
137 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_extension_path));
138 test_extension_path = test_extension_path.AppendASCII("extensions")
139 .AppendASCII("platform_apps")
140 .AppendASCII("minimal");
141 const extensions::Extension* extension =
142 InstallExtension(test_extension_path,
143 1 /* expected_change: new install */);
144 ASSERT_TRUE(extension);
146 AppListService* service = test::GetAppListService();
147 ASSERT_TRUE(service);
148 service->ShowForProfile(browser()->profile());
150 app_list::AppListModel* model = test::GetAppListModel(service);
151 ASSERT_TRUE(model);
152 WatchResultsLookingForItem(model->results(), extension->name());
154 // Ensure a search finds the extension.
155 EXPECT_FALSE(observed_result_);
156 model->search_box()->SetText(base::ASCIIToUTF16("minimal"));
157 EXPECT_TRUE(observed_result_);
159 // Ensure the UI is updated. This is via PostTask in views.
160 base::RunLoop().RunUntilIdle();
162 // Now uninstall and ensure this browser test observes it.
163 UninstallExtension(extension->id());
165 // Allow async AppSearchProvider::UpdateResults to run.
166 base::RunLoop().RunUntilIdle();
168 EXPECT_FALSE(observed_result_);
169 StopWatchingResults();
170 service->DismissAppList();
173 #if defined(OS_CHROMEOS)
175 class AppListControllerGuestModeBrowserTest : public InProcessBrowserTest {
176 public:
177 AppListControllerGuestModeBrowserTest() {}
179 protected:
180 void SetUpCommandLine(base::CommandLine* command_line) override;
182 private:
183 DISALLOW_COPY_AND_ASSIGN(AppListControllerGuestModeBrowserTest);
186 void AppListControllerGuestModeBrowserTest::SetUpCommandLine(
187 base::CommandLine* command_line) {
188 command_line->AppendSwitch(chromeos::switches::kGuestSession);
189 command_line->AppendSwitchASCII(chromeos::switches::kLoginUser,
190 chromeos::login::kGuestUserName);
191 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile,
192 TestingProfile::kTestUserProfileDir);
193 command_line->AppendSwitch(switches::kIncognito);
196 // Test creating the initial app list in guest mode.
197 IN_PROC_BROWSER_TEST_F(AppListControllerGuestModeBrowserTest, Incognito) {
198 AppListService* service = test::GetAppListService();
199 EXPECT_TRUE(service->GetCurrentAppListProfile());
201 service->ShowForProfile(browser()->profile());
202 EXPECT_EQ(browser()->profile(), service->GetCurrentAppListProfile());
205 #endif // defined(OS_CHROMEOS)