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

Unified Diff: chrome/browser/profiles/profile_window_browsertest.cc

Issue 871893003: Browser test for launching guest mode from the User Manager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Test desktop only Created 5 years, 10 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
« no previous file with comments | « no previous file | chrome/browser/ui/browser_command_controller_browsertest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/profiles/profile_window_browsertest.cc
diff --git a/chrome/browser/profiles/profile_window_browsertest.cc b/chrome/browser/profiles/profile_window_browsertest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..bc1da3a285a0b52d9ac17e7454e6cefdd0198345
--- /dev/null
+++ b/chrome/browser/profiles/profile_window_browsertest.cc
@@ -0,0 +1,191 @@
+// Copyright (c) 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/profiles/profile_window.h"
+
+#include "base/command_line.h"
+#include "base/strings/utf_string_conversions.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/chrome_notification_types.h"
+#include "chrome/browser/history/history_service.h"
+#include "chrome/browser/history/history_service_factory.h"
+#include "chrome/browser/profiles/profile_manager.h"
+#include "chrome/browser/search_engines/template_url_service_factory.h"
+#include "chrome/browser/signin/signin_manager_factory.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_finder.h"
+#include "chrome/browser/ui/browser_list.h"
+#include "chrome/test/base/in_process_browser_test.h"
+#include "chrome/test/base/ui_test_utils.h"
+#include "components/history/core/browser/history_db_task.h"
+#include "components/search_engines/template_url_service.h"
+#include "components/signin/core/common/profile_management_switches.h"
+#include "content/public/browser/notification_service.h"
+#include "content/public/test/browser_test_utils.h"
+#include "content/public/test/test_utils.h"
+#include "net/test/spawned_test_server/spawned_test_server.h"
+
+// This test verifies the Desktop implementation of Guest only.
+#if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) && !defined(OS_IOS)
+
+namespace {
+
+// Code related to history borrowed from:
+// chrome/browser/history/history_browsertest.cc
+
+// Note: WaitableEvent is not used for synchronization between the main thread
+// and history backend thread because the history subsystem posts tasks back
+// to the main thread. Had we tried to Signal an event in such a task
+// and Wait for it on the main thread, the task would not run at all because
+// the main thread would be blocked on the Wait call, resulting in a deadlock.
+
+// A task to be scheduled on the history backend thread.
+// Notifies the main thread after all history backend thread tasks have run.
+class WaitForHistoryTask : public history::HistoryDBTask {
+ public:
+ WaitForHistoryTask() {}
+
+ bool RunOnDBThread(history::HistoryBackend* backend,
+ history::HistoryDatabase* db) override {
+ return true;
+ }
+
+ void DoneRunOnMainThread() override { base::MessageLoop::current()->Quit(); }
+
+ private:
+ ~WaitForHistoryTask() override {}
+
+ DISALLOW_COPY_AND_ASSIGN(WaitForHistoryTask);
+};
+
+void WaitForHistoryBackendToRun(Profile* profile) {
+ base::CancelableTaskTracker task_tracker;
+ scoped_ptr<history::HistoryDBTask> task(new WaitForHistoryTask());
+ HistoryService* history = HistoryServiceFactory::GetForProfile(
+ profile, ServiceAccessType::EXPLICIT_ACCESS);
+ history->HistoryService::ScheduleDBTask(task.Pass(), &task_tracker);
+ content::RunMessageLoop();
+}
+
+} // namespace
+
+class ProfileWindowBrowserTest : public InProcessBrowserTest {
+ public:
+ ProfileWindowBrowserTest() {}
+ ~ProfileWindowBrowserTest() override {}
+
+ void SetUpCommandLine(base::CommandLine* command_line) override {
+ InProcessBrowserTest::SetUpCommandLine(command_line);
+ switches::EnableNewAvatarMenuForTesting(
+ base::CommandLine::ForCurrentProcess());
+ }
+
+ Browser* OpenGuestBrowser();
+ void CloseBrowser(Browser* browser);
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ProfileWindowBrowserTest);
+};
+
+Browser* ProfileWindowBrowserTest::OpenGuestBrowser() {
+ size_t num_browsers =
+ BrowserList::GetInstance(chrome::GetActiveDesktop())->size();
+
+ // Create a guest browser nicely. Using CreateProfile() and CreateBrowser()
+ // does incomplete initialization that would lead to
+ // SystemUrlRequestContextGetter being leaked.
+ content::WindowedNotificationObserver browser_creation_observer(
+ chrome::NOTIFICATION_BROWSER_WINDOW_READY,
+ content::NotificationService::AllSources());
+ profiles::SwitchToGuestProfile(chrome::GetActiveDesktop(),
+ ProfileManager::CreateCallback());
+
+ browser_creation_observer.Wait();
+ EXPECT_EQ(num_browsers + 1,
+ BrowserList::GetInstance(chrome::GetActiveDesktop())->size());
+
+ Profile* guest = g_browser_process->profile_manager()->GetProfileByPath(
+ ProfileManager::GetGuestProfilePath());
+ Browser* browser = chrome::FindAnyBrowser(
+ guest, true, chrome::GetActiveDesktop());
+ EXPECT_TRUE(browser);
+
+ // When |browser| closes a BrowsingDataRemover will be created and executed.
+ // It needs a loaded TemplateUrlService or else it hangs on to a
+ // CallbackList::Subscription forever.
+ ui_test_utils::WaitForTemplateURLServiceToLoad(
+ TemplateURLServiceFactory::GetForProfile(guest));
+
+ return browser;
+}
+
+void ProfileWindowBrowserTest::CloseBrowser(Browser* browser) {
+ content::WindowedNotificationObserver window_close_observer(
+ chrome::NOTIFICATION_BROWSER_CLOSED,
+ content::Source<Browser>(browser));
+ browser->window()->Close();
+ window_close_observer.Wait();
+}
+
+IN_PROC_BROWSER_TEST_F(ProfileWindowBrowserTest, OpenGuestBrowser) {
+ EXPECT_TRUE(OpenGuestBrowser());
+}
+
+IN_PROC_BROWSER_TEST_F(ProfileWindowBrowserTest, GuestIsIncognito) {
+ Browser* guest_browser = OpenGuestBrowser();
+ EXPECT_TRUE(guest_browser->profile()->IsOffTheRecord());
+}
+
+IN_PROC_BROWSER_TEST_F(ProfileWindowBrowserTest, GuestIgnoresHistory) {
+ Browser* guest_browser = OpenGuestBrowser();
+
+ ui_test_utils::WaitForHistoryToLoad(HistoryServiceFactory::GetForProfile(
+ guest_browser->profile(), ServiceAccessType::EXPLICIT_ACCESS));
+
+ GURL test_url = ui_test_utils::GetTestUrl(
+ base::FilePath(base::FilePath::kCurrentDirectory),
+ base::FilePath(FILE_PATH_LITERAL("title2.html")));
+
+ ui_test_utils::NavigateToURL(guest_browser, test_url);
+ WaitForHistoryBackendToRun(guest_browser->profile());
+
+ std::vector<GURL> urls =
+ ui_test_utils::HistoryEnumerator(guest_browser->profile()).urls();
+ ASSERT_EQ(0U, urls.size());
+}
+
+IN_PROC_BROWSER_TEST_F(ProfileWindowBrowserTest, GuestClearsCookies) {
+ Browser* guest_browser = OpenGuestBrowser();
+ Profile* guest_profile = guest_browser->profile();
+
+ ASSERT_TRUE(test_server()->Start());
+ GURL url(test_server()->GetURL("set-cookie?cookie1"));
+
+ // Before navigation there are no cookies for the URL.
+ std::string cookie = content::GetCookies(guest_profile, url);
+ ASSERT_EQ("", cookie);
+
+ // After navigation there is a cookie for the URL.
+ ui_test_utils::NavigateToURL(guest_browser, url);
+ cookie = content::GetCookies(guest_profile, url);
+ EXPECT_EQ("cookie1", cookie);
+
+ CloseBrowser(guest_browser);
+
+ // Closing the browser has removed the cookie.
+ cookie = content::GetCookies(guest_profile, url);
+ ASSERT_EQ("", cookie);
+}
+
+IN_PROC_BROWSER_TEST_F(ProfileWindowBrowserTest, GuestCannotSignin) {
+ Browser* guest_browser = OpenGuestBrowser();
+
+ SigninManager* signin_manager = SigninManagerFactory::GetForProfile(
+ guest_browser->profile());
+
+ // Guest profiles can't sign in without a SigninManager.
+ ASSERT_FALSE(signin_manager);
+}
+
+#endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID) && !defined(OS_IOS)
« no previous file with comments | « no previous file | chrome/browser/ui/browser_command_controller_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698