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