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 "base/memory/scoped_ptr.h" | |
6 #include "chrome/browser/ui/browser.h" | |
7 #include "chrome/browser/ui/webui/test_html_dialog_ui_delegate.h" | |
8 #include "chrome/common/url_constants.h" | |
9 #include "chrome/test/base/in_process_browser_test.h" | |
10 #include "chrome/test/base/ui_test_utils.h" | |
11 #include "testing/gmock/include/gmock/gmock.h" | |
12 #include "testing/gtest/include/gtest/gtest.h" | |
13 | |
14 namespace { | |
15 | |
16 class TestDialogClosedDelegate : public test::TestHtmlDialogUIDelegate { | |
17 public: | |
18 TestDialogClosedDelegate() | |
19 : test::TestHtmlDialogUIDelegate(GURL(chrome::kChromeUIChromeURLsURL)), | |
20 dialog_closed_(false) { | |
21 } | |
22 | |
23 // Overridden from HtmlDialogUIDelegate: | |
24 virtual ui::ModalType GetDialogModalType() const OVERRIDE { | |
25 return ui::MODAL_TYPE_NONE; | |
26 } | |
27 | |
28 // Overridden from HtmlDialogUIDelegate: | |
29 virtual void OnDialogClosed(const std::string& json_retval) OVERRIDE { | |
30 dialog_closed_ = true; | |
31 } | |
32 | |
33 bool dialog_closed() { | |
34 return dialog_closed_; | |
35 } | |
36 | |
37 private: | |
38 bool dialog_closed_; | |
39 }; | |
40 | |
41 } // namespace | |
42 | |
43 class HtmlDialogControllerBrowserTest : public InProcessBrowserTest { | |
44 public: | |
45 HtmlDialogControllerBrowserTest() {} | |
46 }; | |
47 | |
48 // Tests that an HtmlDialog can be shown for an incognito browser and that when | |
49 // that browser is closed the dialog created by that browser is closed. | |
50 IN_PROC_BROWSER_TEST_F(HtmlDialogControllerBrowserTest, IncognitoBrowser) { | |
51 Browser* browser = CreateIncognitoBrowser(); | |
52 scoped_ptr<TestDialogClosedDelegate> delegate(new TestDialogClosedDelegate()); | |
53 | |
54 // Create the dialog and make sure the initial "closed" state is what we | |
55 // expect. | |
56 browser->BrowserShowHtmlDialog(delegate.get(), NULL, STYLE_GENERIC); | |
57 ui_test_utils::RunAllPendingInMessageLoop(); | |
58 ASSERT_FALSE(delegate->dialog_closed()); | |
59 | |
60 // Closing the browser should close the dialogs associated with that browser. | |
61 browser->CloseWindow(); | |
62 ui_test_utils::RunAllPendingInMessageLoop(); | |
63 ASSERT_TRUE(delegate->dialog_closed()); | |
64 } | |
OLD | NEW |