OLD | NEW |
| (Empty) |
1 // Copyright 2017 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. | |
4 | |
5 #include "chrome/browser/ui/views/sync/profile_signin_confirmation_dialog_views.
h" | |
6 | |
7 #include "base/command_line.h" | |
8 #include "base/strings/utf_string_conversions.h" | |
9 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | |
10 #include "chrome/browser/ui/sync/profile_signin_confirmation_helper.h" | |
11 #include "chrome/browser/ui/tab_dialogs.h" | |
12 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
13 #include "chrome/browser/ui/test/test_browser_dialog.h" | |
14 #include "components/bookmarks/browser/bookmark_model.h" | |
15 #include "ui/base/ui_base_switches.h" | |
16 | |
17 namespace { | |
18 | |
19 // Test delegate passed to the confirmation dialog to report back the result. | |
20 class TestSigninDialogDelegate : public ui::ProfileSigninConfirmationDelegate { | |
21 public: | |
22 TestSigninDialogDelegate() {} | |
23 virtual ~TestSigninDialogDelegate() {} | |
24 | |
25 void OnCancelSignin() override {} | |
26 void OnContinueSignin() override {} | |
27 void OnSigninWithNewProfile() override {} | |
28 | |
29 private: | |
30 DISALLOW_COPY_AND_ASSIGN(TestSigninDialogDelegate); | |
31 }; | |
32 | |
33 } // namespace | |
34 | |
35 class ProfileSigninConfirmationDialogTest : public DialogBrowserTest { | |
36 public: | |
37 ProfileSigninConfirmationDialogTest() {} | |
38 | |
39 // content::BrowserTestBase: | |
40 void SetUpCommandLine(base::CommandLine* command_line) override { | |
41 command_line->AppendSwitch(switches::kExtendMdToSecondaryUi); | |
42 } | |
43 | |
44 // DialogBrowserTest: | |
45 void ShowDialog(const std::string& name) override { | |
46 Profile* profile = browser()->profile(); | |
47 | |
48 // Add a bookmark to ensure CheckShouldPromptForNewProfile() returns true. | |
49 bookmarks::BookmarkModel* bookmarks = | |
50 BookmarkModelFactory::GetForBrowserContext(profile); | |
51 bookmarks->AddURL(bookmarks->bookmark_bar_node(), 0, | |
52 base::ASCIIToUTF16("title"), | |
53 GURL("http://www.example.com")); | |
54 | |
55 content::WebContents* web_contents = | |
56 browser()->tab_strip_model()->GetActiveWebContents(); | |
57 TabDialogs::FromWebContents(web_contents) | |
58 ->ShowProfileSigninConfirmation( | |
59 browser(), profile, "username@example.com", | |
60 base::MakeUnique<TestSigninDialogDelegate>()); | |
61 } | |
62 | |
63 private: | |
64 DISALLOW_COPY_AND_ASSIGN(ProfileSigninConfirmationDialogTest); | |
65 }; | |
66 | |
67 // Test that calls ShowDialog("default"). Interactive when run via | |
68 // browser_tests --gtest_filter=BrowserDialogTest.Invoke --interactive | |
69 // --dialog=ProfileSigninConfirmationDialogTest.InvokeDialog_default | |
70 IN_PROC_BROWSER_TEST_F(ProfileSigninConfirmationDialogTest, | |
71 InvokeDialog_default) { | |
72 RunDialog(); | |
73 } | |
OLD | NEW |