| 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 #import "chrome/browser/ui/cocoa/html_dialog_window_controller.h" | |
| 6 | |
| 7 #include <string> | |
| 8 #include <vector> | |
| 9 | |
| 10 #import <Cocoa/Cocoa.h> | |
| 11 | |
| 12 #import "base/mac/scoped_nsautorelease_pool.h" | |
| 13 #include "base/sys_string_conversions.h" | |
| 14 #include "base/utf_string_conversions.h" | |
| 15 #include "chrome/browser/ui/browser.h" | |
| 16 #include "chrome/browser/ui/cocoa/cocoa_test_helper.h" | |
| 17 #include "chrome/browser/ui/webui/html_dialog_ui.h" | |
| 18 #include "chrome/test/base/browser_with_test_window_test.h" | |
| 19 #include "chrome/test/base/testing_profile.h" | |
| 20 #include "content/public/browser/web_ui.h" | |
| 21 #include "content/public/browser/web_ui_message_handler.h" | |
| 22 #include "googleurl/src/gurl.h" | |
| 23 #include "testing/gmock/include/gmock/gmock.h" | |
| 24 #include "testing/gtest/include/gtest/gtest.h" | |
| 25 #include "ui/gfx/size.h" | |
| 26 | |
| 27 using content::WebContents; | |
| 28 using content::WebUIMessageHandler; | |
| 29 | |
| 30 namespace { | |
| 31 | |
| 32 class MockDelegate : public HtmlDialogUIDelegate { | |
| 33 public: | |
| 34 MOCK_CONST_METHOD0(GetDialogModalType, ui::ModalType()); | |
| 35 MOCK_CONST_METHOD0(GetDialogTitle, string16()); | |
| 36 MOCK_CONST_METHOD0(GetDialogContentURL, GURL()); | |
| 37 MOCK_CONST_METHOD1(GetWebUIMessageHandlers, | |
| 38 void(std::vector<WebUIMessageHandler*>*)); | |
| 39 MOCK_CONST_METHOD1(GetDialogSize, void(gfx::Size*)); | |
| 40 MOCK_CONST_METHOD0(GetDialogArgs, std::string()); | |
| 41 MOCK_METHOD1(OnDialogClosed, void(const std::string& json_retval)); | |
| 42 MOCK_METHOD2(OnCloseContents, | |
| 43 void(WebContents* source, bool* out_close_dialog)); | |
| 44 MOCK_CONST_METHOD0(ShouldShowDialogTitle, bool()); | |
| 45 }; | |
| 46 | |
| 47 class HtmlDialogWindowControllerTest : public BrowserWithTestWindowTest { | |
| 48 public: | |
| 49 virtual void SetUp() { | |
| 50 BrowserWithTestWindowTest::SetUp(); | |
| 51 CocoaTest::BootstrapCocoa(); | |
| 52 title_ = ASCIIToUTF16("Mock Title"); | |
| 53 size_ = gfx::Size(50, 100); | |
| 54 gurl_ = GURL(""); | |
| 55 } | |
| 56 | |
| 57 protected: | |
| 58 string16 title_; | |
| 59 gfx::Size size_; | |
| 60 GURL gurl_; | |
| 61 | |
| 62 // Order here is important. | |
| 63 MockDelegate delegate_; | |
| 64 }; | |
| 65 | |
| 66 using ::testing::_; | |
| 67 using ::testing::Return; | |
| 68 using ::testing::SetArgumentPointee; | |
| 69 | |
| 70 // TODO(akalin): We can't test much more than the below without a real browser. | |
| 71 // In particular, GetWebUIMessageHandlers() and GetDialogArgs() are never | |
| 72 // called. This should be fixed. | |
| 73 | |
| 74 TEST_F(HtmlDialogWindowControllerTest, showDialog) { | |
| 75 // We want to make sure html_dialog_window_controller below gets | |
| 76 // destroyed before delegate_, so we specify our own autorelease pool. | |
| 77 // | |
| 78 // TODO(dmaclach): Remove this once | |
| 79 // http://code.google.com/p/chromium/issues/detail?id=26133 is fixed. | |
| 80 base::mac::ScopedNSAutoreleasePool release_pool; | |
| 81 | |
| 82 EXPECT_CALL(delegate_, GetDialogTitle()) | |
| 83 .WillOnce(Return(title_)); | |
| 84 EXPECT_CALL(delegate_, GetDialogSize(_)) | |
| 85 .WillOnce(SetArgumentPointee<0>(size_)); | |
| 86 EXPECT_CALL(delegate_, GetDialogContentURL()) | |
| 87 .WillOnce(Return(gurl_)); | |
| 88 EXPECT_CALL(delegate_, OnDialogClosed(_)) | |
| 89 .Times(1); | |
| 90 | |
| 91 HtmlDialogWindowController* html_dialog_window_controller = | |
| 92 [[HtmlDialogWindowController alloc] initWithDelegate:&delegate_ | |
| 93 profile:profile() | |
| 94 browser:browser()]; | |
| 95 | |
| 96 [html_dialog_window_controller loadDialogContents]; | |
| 97 [html_dialog_window_controller showWindow:nil]; | |
| 98 [html_dialog_window_controller close]; | |
| 99 } | |
| 100 | |
| 101 } // namespace | |
| OLD | NEW |