| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 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 #include "gtest/gtest.h" | 5 #include "gtest/gtest.h" |
| 6 #include "gmock/gmock.h" | 6 #include "gmock/gmock.h" |
| 7 #include "chrome_frame/chrome_frame_automation.h" | 7 #include "chrome_frame/chrome_frame_automation.h" |
| 8 #include "chrome_frame/chrome_frame_npapi.h" | 8 #include "chrome_frame/chrome_frame_npapi.h" |
| 9 #include "chrome_frame/ff_privilege_check.h" | 9 #include "chrome_frame/ff_privilege_check.h" |
| 10 | 10 |
| 11 TEST(ChromeFrameNPAPI, DoesNotCrashOnConstruction) { | 11 TEST(ChromeFrameNPAPI, DoesNotCrashOnConstruction) { |
| 12 ChromeFrameNPAPI* api = new ChromeFrameNPAPI(); | 12 ChromeFrameNPAPI* api = new ChromeFrameNPAPI(); |
| 13 delete api; | 13 delete api; |
| 14 } | 14 } |
| 15 | 15 |
| 16 | 16 |
| 17 // All mocks in the anonymous namespace. | 17 // All mocks in the anonymous namespace. |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 using ::testing::_; | 20 using ::testing::_; |
| 21 using ::testing::Eq; | 21 using ::testing::Eq; |
| 22 using ::testing::Field; |
| 22 using ::testing::Invoke; | 23 using ::testing::Invoke; |
| 23 using ::testing::Return; | 24 using ::testing::Return; |
| 24 using ::testing::StrEq; | 25 using ::testing::StrEq; |
| 25 | 26 |
| 26 // Make mocking privilege test easy. | 27 // Make mocking privilege test easy. |
| 27 class MockPrivilegeTest { | 28 class MockPrivilegeTest { |
| 28 public: | 29 public: |
| 29 MockPrivilegeTest() { | 30 MockPrivilegeTest() { |
| 30 CHECK(current_ == NULL); | 31 CHECK(current_ == NULL); |
| 31 current_ = this; | 32 current_ = this; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 | 73 |
| 73 ChromeFrameAutomationClient* CreateAutomationClient() { | 74 ChromeFrameAutomationClient* CreateAutomationClient() { |
| 74 return mock_automation_client_; | 75 return mock_automation_client_; |
| 75 } | 76 } |
| 76 | 77 |
| 77 ChromeFrameAutomationClient* mock_automation_client_; | 78 ChromeFrameAutomationClient* mock_automation_client_; |
| 78 }; | 79 }; |
| 79 | 80 |
| 80 class MockAutomationClient: public ChromeFrameAutomationClient { | 81 class MockAutomationClient: public ChromeFrameAutomationClient { |
| 81 public: | 82 public: |
| 82 MOCK_METHOD6(Initialize, bool(ChromeFrameDelegate*, int, bool, | 83 MOCK_METHOD2(Initialize, bool(ChromeFrameDelegate*, |
| 83 const FilePath&, const std::wstring&, | 84 const ChromeFrameLaunchParams&)); |
| 84 bool)); | |
| 85 MOCK_METHOD1(SetEnableExtensionAutomation, | 85 MOCK_METHOD1(SetEnableExtensionAutomation, |
| 86 void(const std::vector<std::string>&)); // NOLINT | 86 void(const std::vector<std::string>&)); // NOLINT |
| 87 }; | 87 }; |
| 88 | 88 |
| 89 class MockProxyService: public NpProxyService { | 89 class MockProxyService: public NpProxyService { |
| 90 public: | 90 public: |
| 91 MOCK_METHOD2(Initialize, bool(NPP instance, ChromeFrameAutomationClient*)); | 91 MOCK_METHOD2(Initialize, bool(NPP instance, ChromeFrameAutomationClient*)); |
| 92 }; | 92 }; |
| 93 | 93 |
| 94 | 94 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 119 EXPECT_CALL(mock_api, GetLocation()) | 119 EXPECT_CALL(mock_api, GetLocation()) |
| 120 .WillOnce(Return(std::string("http://www.google.com"))); | 120 .WillOnce(Return(std::string("http://www.google.com"))); |
| 121 EXPECT_CALL(mock_api, CreatePrefService()) | 121 EXPECT_CALL(mock_api, CreatePrefService()) |
| 122 .WillOnce(Return(mock_proxy)); | 122 .WillOnce(Return(mock_proxy)); |
| 123 EXPECT_CALL(mock_api, GetBrowserIncognitoMode()) | 123 EXPECT_CALL(mock_api, GetBrowserIncognitoMode()) |
| 124 .WillOnce(Return(is_incognito)); | 124 .WillOnce(Return(is_incognito)); |
| 125 | 125 |
| 126 EXPECT_CALL(*mock_proxy, Initialize(_, _)).WillRepeatedly(Return(false)); | 126 EXPECT_CALL(*mock_proxy, Initialize(_, _)).WillRepeatedly(Return(false)); |
| 127 | 127 |
| 128 EXPECT_CALL(*mock_automation, | 128 EXPECT_CALL(*mock_automation, |
| 129 Initialize(_, _, true, _, StrEq(extra_args), false)) | 129 Initialize(_, AllOf( |
| 130 Field(&ChromeFrameLaunchParams::perform_version_check, true), |
| 131 Field(&ChromeFrameLaunchParams::extra_chrome_arguments, |
| 132 StrEq(extra_args)), |
| 133 Field(&ChromeFrameLaunchParams::incognito_mode, is_incognito), |
| 134 Field(&ChromeFrameLaunchParams::is_widget_mode, true)))) |
| 130 .WillOnce(Return(true)); | 135 .WillOnce(Return(true)); |
| 131 | 136 |
| 132 if (expect_privilege_check) { | 137 if (expect_privilege_check) { |
| 133 EXPECT_CALL(mock_priv, IsFireFoxPrivilegedInvocation(_)) | 138 EXPECT_CALL(mock_priv, IsFireFoxPrivilegedInvocation(_)) |
| 134 .WillOnce(Return(is_privileged)); | 139 .WillOnce(Return(is_privileged)); |
| 135 } else { | 140 } else { |
| 136 EXPECT_CALL(mock_priv, IsFireFoxPrivilegedInvocation(_)) | 141 EXPECT_CALL(mock_priv, IsFireFoxPrivilegedInvocation(_)) |
| 137 .Times(0); // Fail if privilege check invoked. | 142 .Times(0); // Fail if privilege check invoked. |
| 138 } | 143 } |
| 139 } | 144 } |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 // And fething it should return the value we just set. | 547 // And fething it should return the value we just set. |
| 543 VOID_TO_NPVARIANT(var); | 548 VOID_TO_NPVARIANT(var); |
| 544 EXPECT_TRUE(mock_api.GetProperty(kOnPrivateMessageId, &var)); | 549 EXPECT_TRUE(mock_api.GetProperty(kOnPrivateMessageId, &var)); |
| 545 EXPECT_TRUE(NPVARIANT_IS_OBJECT(var)); | 550 EXPECT_TRUE(NPVARIANT_IS_OBJECT(var)); |
| 546 EXPECT_EQ(kMockNPObject, NPVARIANT_TO_OBJECT(var)); | 551 EXPECT_EQ(kMockNPObject, NPVARIANT_TO_OBJECT(var)); |
| 547 | 552 |
| 548 mock_api.Uninitialize(); | 553 mock_api.Uninitialize(); |
| 549 } | 554 } |
| 550 | 555 |
| 551 // TODO(siggi): test invoking postPrivateMessage. | 556 // TODO(siggi): test invoking postPrivateMessage. |
| OLD | NEW |