OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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/webui/sync_promo/sync_promo_dialog.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/message_loop.h" | |
9 #include "chrome/browser/ui/browser.h" | |
10 #include "chrome/browser/ui/browser_dialogs.h" | |
11 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" | |
12 #include "chrome/test/base/in_process_browser_test.h" | |
13 #include "content/public/browser/web_contents.h" | |
14 | |
15 namespace { | |
16 | |
17 GURL GetSyncPromoURL() { | |
18 return SyncPromoUI::GetSyncPromoURL(GURL("http://a/"), true, ""); | |
19 } | |
20 | |
21 void OpenLink(content::WebContents* source) { | |
22 content::Referrer referrer(GURL(), WebKit::WebReferrerPolicyAlways); | |
23 content::OpenURLParams params(GURL("http://b/"), referrer, NEW_FOREGROUND_TAB, | |
24 content::PAGE_TRANSITION_LINK, true); | |
25 source->GetDelegate()->OpenURLFromTab(source, params); | |
26 } | |
27 | |
28 class TestSyncPromoDialog : public SyncPromoDialog { | |
29 public: | |
30 TestSyncPromoDialog(Profile* profile, GURL url) | |
31 : SyncPromoDialog(profile, url), | |
32 on_load_close_(false), | |
33 on_load_open_link_(false) { | |
34 } | |
35 | |
36 void set_on_load_close(bool flag) { on_load_close_ = flag; } | |
37 void set_on_load_open_link(bool flag) { on_load_open_link_ = flag; } | |
38 | |
39 virtual void OnLoadingStateChanged(content::WebContents* source) OVERRIDE { | |
40 if (!source || source->IsLoading()) | |
41 return; | |
42 if (on_load_close_) { | |
43 MessageLoop::current()->PostTask( | |
44 FROM_HERE, base::Bind(&browser::CloseHtmlDialog, window())); | |
45 } else if (on_load_open_link_) { | |
46 MessageLoop::current()->PostTask( | |
47 FROM_HERE, base::Bind(&OpenLink, source)); | |
48 } | |
49 } | |
50 | |
51 private: | |
52 bool on_load_close_; | |
53 bool on_load_open_link_; | |
54 }; | |
55 | |
56 typedef InProcessBrowserTest SyncPromoDialogBrowserTest; | |
57 | |
58 // Test that closing the dialog window spawns a new browser and end the modal | |
59 // session. | |
60 IN_PROC_BROWSER_TEST_F(SyncPromoDialogBrowserTest, Close) { | |
61 TestSyncPromoDialog dialog(browser()->profile(), GetSyncPromoURL()); | |
62 SyncPromoUI::DidShowSyncPromoAtStartup(browser()->profile()); | |
63 dialog.set_on_load_close(true); | |
64 dialog.ShowDialog(); | |
65 | |
66 EXPECT_FALSE(dialog.spawned_browser()); | |
67 EXPECT_FALSE(dialog.sync_promo_was_closed()); | |
68 } | |
69 | |
70 // Test that clicking a link in the dialog window spawns a new browser window | |
71 // and ends the modal session. | |
72 IN_PROC_BROWSER_TEST_F(SyncPromoDialogBrowserTest, OpenLink) { | |
73 TestSyncPromoDialog dialog(browser()->profile(), GetSyncPromoURL()); | |
74 SyncPromoUI::DidShowSyncPromoAtStartup(browser()->profile()); | |
75 dialog.set_on_load_open_link(true); | |
76 dialog.ShowDialog(); | |
77 | |
78 EXPECT_TRUE(dialog.spawned_browser()); | |
79 EXPECT_FALSE(dialog.sync_promo_was_closed()); | |
80 } | |
81 | |
82 } // namespace | |
OLD | NEW |