| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "app/table_model_observer.h" | 5 #include "app/table_model_observer.h" |
| 6 #include "base/auto_reset.h" | 6 #include "base/auto_reset.h" |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/mock_plugin_exceptions_table_model.h" | 9 #include "chrome/browser/mock_plugin_exceptions_table_model.h" |
| 10 #include "chrome/common/chrome_switches.h" | 10 #include "chrome/common/chrome_switches.h" |
| 11 #include "chrome/common/pref_names.h" | 11 #include "chrome/common/pref_names.h" |
| 12 #include "chrome/test/testing_pref_service.h" | 12 #include "chrome/test/testing_pref_service.h" |
| 13 #include "chrome/test/testing_profile.h" | 13 #include "chrome/test/testing_profile.h" |
| 14 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "webkit/glue/plugins/plugin_group.h" | 16 #include "webkit/glue/plugins/plugin_group.h" |
| 17 #include "webkit/glue/plugins/webplugininfo.h" | 17 #include "webkit/glue/plugins/webplugininfo.h" |
| 18 | 18 |
| 19 // Can't be an internal namespace because PluginExceptionsTableModel declares | 19 // Can't be an internal namespace because PluginExceptionsTableModel declares |
| 20 // as a friend. | 20 // as a friend. |
| 21 namespace plugin_test_internal { | 21 namespace plugin_test_internal { |
| 22 | 22 |
| 23 using ::testing::_; | 23 using ::testing::_; |
| 24 using ::testing::InSequence; | |
| 25 using ::testing::Invoke; | 24 using ::testing::Invoke; |
| 26 | 25 |
| 27 class MockTableModelObserver : public TableModelObserver { | 26 class MockTableModelObserver : public TableModelObserver { |
| 28 public: | 27 public: |
| 29 explicit MockTableModelObserver(TableModel* model) | 28 explicit MockTableModelObserver(TableModel* model) |
| 30 : model_(model) { | 29 : model_(model) { |
| 31 ON_CALL(*this, OnItemsRemoved(_, _)) | 30 ON_CALL(*this, OnItemsRemoved(_, _)) |
| 32 .WillByDefault( | 31 .WillByDefault( |
| 33 Invoke(this, &MockTableModelObserver::CheckOnItemsRemoved)); | 32 Invoke(this, &MockTableModelObserver::CheckOnItemsRemoved)); |
| 34 } | 33 } |
| 35 | 34 |
| 36 MOCK_METHOD0(OnModelChanged, void()); | 35 MOCK_METHOD0(OnModelChanged, void()); |
| 37 MOCK_METHOD2(OnItemsChanged, void(int start, int length)); | 36 MOCK_METHOD2(OnItemsChanged, void(int start, int length)); |
| 38 MOCK_METHOD2(OnItemsAdded, void(int start, int length)); | 37 MOCK_METHOD2(OnItemsAdded, void(int start, int length)); |
| 39 MOCK_METHOD2(OnItemsRemoved, void(int start, int length)); | 38 MOCK_METHOD2(OnItemsRemoved, void(int start, int length)); |
| 40 | 39 |
| 41 private: | 40 private: |
| 42 void CheckOnItemsRemoved(int start, int length) { | 41 void CheckOnItemsRemoved(int start, int length) { |
| 43 if (!model_) | 42 if (!model_) |
| 44 return; | 43 return; |
| 45 // This method is called *after* the items have been removed, so we check if | 44 // This method is called *after* the items have been removed, so we check if |
| 46 // the first removed item was still inside the correct range. | 45 // the first removed item was still inside the correct range. |
| 47 EXPECT_LT(start, model_->RowCount() + 1); | 46 EXPECT_LT(start, model_->RowCount() + 1); |
| 48 } | 47 } |
| 49 | 48 |
| 50 TableModel* model_; | 49 TableModel* model_; |
| 51 }; | 50 }; |
| 52 | 51 |
| 52 } // namespace plugin_test_internal |
| 53 |
| 54 using ::testing::InSequence; |
| 55 |
| 53 class PluginExceptionsTableModelTest : public testing::Test { | 56 class PluginExceptionsTableModelTest : public testing::Test { |
| 54 public: | 57 public: |
| 55 PluginExceptionsTableModelTest() | 58 PluginExceptionsTableModelTest() |
| 56 : ui_thread_(BrowserThread::UI, &message_loop_), | 59 : ui_thread_(BrowserThread::UI, &message_loop_), |
| 57 command_line_(CommandLine::ForCurrentProcess(), | 60 command_line_(CommandLine::ForCurrentProcess(), |
| 58 *CommandLine::ForCurrentProcess()) {} | 61 *CommandLine::ForCurrentProcess()) {} |
| 59 | 62 |
| 60 virtual void SetUp() { | 63 virtual void SetUp() { |
| 61 CommandLine::ForCurrentProcess()->AppendSwitch( | 64 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 62 switches::kEnableResourceContentSettings); | 65 switches::kEnableResourceContentSettings); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 private: | 150 private: |
| 148 AutoReset<CommandLine> command_line_; | 151 AutoReset<CommandLine> command_line_; |
| 149 }; | 152 }; |
| 150 | 153 |
| 151 TEST_F(PluginExceptionsTableModelTest, Basic) { | 154 TEST_F(PluginExceptionsTableModelTest, Basic) { |
| 152 EXPECT_EQ(3, table_model_->RowCount()); | 155 EXPECT_EQ(3, table_model_->RowCount()); |
| 153 CheckInvariants(); | 156 CheckInvariants(); |
| 154 } | 157 } |
| 155 | 158 |
| 156 TEST_F(PluginExceptionsTableModelTest, RemoveOneRow) { | 159 TEST_F(PluginExceptionsTableModelTest, RemoveOneRow) { |
| 157 MockTableModelObserver observer(table_model_.get()); | 160 plugin_test_internal::MockTableModelObserver observer(table_model_.get()); |
| 158 table_model_->SetObserver(&observer); | 161 table_model_->SetObserver(&observer); |
| 159 | 162 |
| 160 EXPECT_CALL(observer, OnItemsRemoved(1, 1)); | 163 EXPECT_CALL(observer, OnItemsRemoved(1, 1)); |
| 161 RemoveRowsTableModel::Rows rows; | 164 RemoveRowsTableModel::Rows rows; |
| 162 rows.insert(1); | 165 rows.insert(1); |
| 163 table_model_->RemoveRows(rows); | 166 table_model_->RemoveRows(rows); |
| 164 EXPECT_EQ(2, table_model_->RowCount()); | 167 EXPECT_EQ(2, table_model_->RowCount()); |
| 165 EXPECT_EQ(2, static_cast<int>(table_model_->GetGroups().size())); | 168 EXPECT_EQ(2, static_cast<int>(table_model_->GetGroups().size())); |
| 166 CheckInvariants(); | 169 CheckInvariants(); |
| 167 table_model_->SetObserver(NULL); | 170 table_model_->SetObserver(NULL); |
| 168 } | 171 } |
| 169 | 172 |
| 170 TEST_F(PluginExceptionsTableModelTest, RemoveLastRowInGroup) { | 173 TEST_F(PluginExceptionsTableModelTest, RemoveLastRowInGroup) { |
| 171 MockTableModelObserver observer(table_model_.get()); | 174 plugin_test_internal::MockTableModelObserver observer(table_model_.get()); |
| 172 table_model_->SetObserver(&observer); | 175 table_model_->SetObserver(&observer); |
| 173 | 176 |
| 174 EXPECT_CALL(observer, OnModelChanged()); | 177 EXPECT_CALL(observer, OnModelChanged()); |
| 175 RemoveRowsTableModel::Rows rows; | 178 RemoveRowsTableModel::Rows rows; |
| 176 rows.insert(0); | 179 rows.insert(0); |
| 177 table_model_->RemoveRows(rows); | 180 table_model_->RemoveRows(rows); |
| 178 EXPECT_EQ(2, table_model_->RowCount()); | 181 EXPECT_EQ(2, table_model_->RowCount()); |
| 179 EXPECT_EQ(1, static_cast<int>(table_model_->GetGroups().size())); | 182 EXPECT_EQ(1, static_cast<int>(table_model_->GetGroups().size())); |
| 180 CheckInvariants(); | 183 CheckInvariants(); |
| 181 | 184 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 195 rows.insert(2); | 198 rows.insert(2); |
| 196 table_model_->RemoveRows(rows); | 199 table_model_->RemoveRows(rows); |
| 197 EXPECT_EQ(1, table_model_->RowCount()); | 200 EXPECT_EQ(1, table_model_->RowCount()); |
| 198 EXPECT_EQ(1, static_cast<int>(table_model_->GetGroups().size())); | 201 EXPECT_EQ(1, static_cast<int>(table_model_->GetGroups().size())); |
| 199 CheckInvariants(); | 202 CheckInvariants(); |
| 200 | 203 |
| 201 table_model_->SetObserver(NULL); | 204 table_model_->SetObserver(NULL); |
| 202 } | 205 } |
| 203 | 206 |
| 204 TEST_F(PluginExceptionsTableModelTest, RemoveAllRows) { | 207 TEST_F(PluginExceptionsTableModelTest, RemoveAllRows) { |
| 205 MockTableModelObserver observer(table_model_.get()); | 208 plugin_test_internal::MockTableModelObserver observer(table_model_.get()); |
| 206 table_model_->SetObserver(&observer); | 209 table_model_->SetObserver(&observer); |
| 207 | 210 |
| 208 EXPECT_CALL(observer, OnModelChanged()); | 211 EXPECT_CALL(observer, OnModelChanged()); |
| 209 table_model_->RemoveAll(); | 212 table_model_->RemoveAll(); |
| 210 EXPECT_EQ(0, table_model_->RowCount()); | 213 EXPECT_EQ(0, table_model_->RowCount()); |
| 211 EXPECT_EQ(0, static_cast<int>(table_model_->GetGroups().size())); | 214 EXPECT_EQ(0, static_cast<int>(table_model_->GetGroups().size())); |
| 212 CheckInvariants(); | 215 CheckInvariants(); |
| 213 table_model_->SetObserver(NULL); | 216 table_model_->SetObserver(NULL); |
| 214 } | 217 } |
| 215 | |
| 216 } // namespace plugin_test_internal | |
| OLD | NEW |