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