Index: chrome/browser/cocoa/table_model_array_controller_unittest.mm |
diff --git a/chrome/browser/cocoa/table_model_array_controller_unittest.mm b/chrome/browser/cocoa/table_model_array_controller_unittest.mm |
new file mode 100644 |
index 0000000000000000000000000000000000000000..4f32358e2122421a804913a1e3577208de86a44f |
--- /dev/null |
+++ b/chrome/browser/cocoa/table_model_array_controller_unittest.mm |
@@ -0,0 +1,168 @@ |
+// Copyright (c) 2010 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#import "chrome/browser/cocoa/table_model_array_controller.h" |
+ |
+#include "base/auto_reset.h" |
+#include "base/command_line.h" |
+#include "base/utf_string_conversions.h" |
+#include "chrome/browser/cocoa/browser_test_helper.h" |
+#import "chrome/browser/cocoa/cocoa_test_helper.h" |
+#include "chrome/browser/mock_plugin_exceptions_table_model.h" |
+#include "chrome/common/chrome_switches.h" |
+#include "chrome/test/testing_profile.h" |
+#include "grit/generated_resources.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+#include "testing/gtest_mac.h" |
+#include "webkit/glue/plugins/webplugininfo.h" |
+ |
+namespace { |
+ |
+class TableModelArrayControllerTest : public CocoaTest { |
+ public: |
+ TableModelArrayControllerTest() |
+ : command_line_(CommandLine::ForCurrentProcess(), |
+ *CommandLine::ForCurrentProcess()) {} |
+ |
+ virtual void SetUp() { |
+ CocoaTest::SetUp(); |
+ |
+ CommandLine::ForCurrentProcess()->AppendSwitch( |
+ switches::kEnableResourceContentSettings); |
+ |
+ TestingProfile* profile = browser_helper_.profile(); |
+ HostContentSettingsMap* map = profile->GetHostContentSettingsMap(); |
+ |
+ HostContentSettingsMap::Pattern example_com("[*.]example.com"); |
+ HostContentSettingsMap::Pattern moose_org("[*.]moose.org"); |
+ map->SetContentSetting(example_com, |
+ CONTENT_SETTINGS_TYPE_PLUGINS, |
+ "foo", |
+ CONTENT_SETTING_ALLOW); |
+ map->SetContentSetting(moose_org, |
+ CONTENT_SETTINGS_TYPE_PLUGINS, |
+ "bar", |
+ CONTENT_SETTING_BLOCK); |
+ map->SetContentSetting(example_com, |
+ CONTENT_SETTINGS_TYPE_PLUGINS, |
+ "bar", |
+ CONTENT_SETTING_ALLOW); |
+ |
+ model_.reset(new MockPluginExceptionsTableModel(map, NULL)); |
+ |
+ std::vector<WebPluginInfo> plugins; |
+ WebPluginInfo foo_plugin; |
+ foo_plugin.path = FilePath(FILE_PATH_LITERAL("foo")); |
+ foo_plugin.name = ASCIIToUTF16("FooPlugin"); |
+ foo_plugin.enabled = true; |
+ plugins.push_back(foo_plugin); |
+ WebPluginInfo bar_plugin; |
+ bar_plugin.path = FilePath(FILE_PATH_LITERAL("bar")); |
+ bar_plugin.name = ASCIIToUTF16("BarPlugin"); |
+ bar_plugin.enabled = true; |
+ plugins.push_back(bar_plugin); |
+ WebPluginInfo blurp_plugin; |
+ blurp_plugin.path = FilePath(FILE_PATH_LITERAL("blurp")); |
+ blurp_plugin.name = ASCIIToUTF16("BlurpPlugin"); |
+ blurp_plugin.enabled = true; |
+ plugins.push_back(blurp_plugin); |
+ |
+ model_->set_plugins(plugins); |
+ model_->LoadSettings(); |
+ |
+ id content = [NSMutableArray array]; |
+ controller_.reset( |
+ [[TableModelArrayController alloc] initWithContent:content]); |
+ NSDictionary* columns = [NSDictionary dictionaryWithObjectsAndKeys: |
+ [NSNumber numberWithInt:IDS_EXCEPTIONS_HOSTNAME_HEADER], @"title", |
+ [NSNumber numberWithInt:IDS_EXCEPTIONS_ACTION_HEADER], @"action", |
+ nil]; |
+ [controller_.get() bindToTableModel:model_.get() |
+ withColumns:columns |
+ groupTitleColumn:@"title"]; |
+ } |
+ |
+ protected: |
+ BrowserTestHelper browser_helper_; |
+ scoped_ptr<MockPluginExceptionsTableModel> model_; |
+ scoped_nsobject<TableModelArrayController> controller_; |
+ |
+ private: |
+ AutoReset<CommandLine> command_line_; |
+}; |
+ |
+TEST_F(TableModelArrayControllerTest, CheckTitles) { |
+ NSArray* titles = [[controller_.get() arrangedObjects] valueForKey:@"title"]; |
+ EXPECT_NSEQ(@"(\n" |
+ @" FooPlugin,\n" |
+ @" \"[*.]example.com\",\n" |
+ @" BarPlugin,\n" |
+ @" \"[*.]example.com\",\n" |
+ @" \"[*.]moose.org\"\n" |
+ @")", |
+ [titles description]); |
+} |
+ |
+TEST_F(TableModelArrayControllerTest, RemoveRows) { |
+ NSArrayController* controller = controller_.get(); |
+ [controller setSelectionIndex:1]; |
+ [controller remove:nil]; |
+ NSArray* titles = [[controller arrangedObjects] valueForKey:@"title"]; |
+ EXPECT_NSEQ(@"(\n" |
+ @" BarPlugin,\n" |
+ @" \"[*.]example.com\",\n" |
+ @" \"[*.]moose.org\"\n" |
+ @")", |
+ [titles description]); |
+ |
+ [controller setSelectionIndex:2]; |
+ [controller remove:nil]; |
+ titles = [[controller arrangedObjects] valueForKey:@"title"]; |
+ EXPECT_NSEQ(@"(\n" |
+ @" BarPlugin,\n" |
+ @" \"[*.]example.com\"\n" |
+ @")", |
+ [titles description]); |
+} |
+ |
+TEST_F(TableModelArrayControllerTest, RemoveAll) { |
+ [controller_.get() removeAll:nil]; |
+ EXPECT_EQ(0u, [[controller_.get() arrangedObjects] count]); |
+} |
+ |
+TEST_F(TableModelArrayControllerTest, AddException) { |
+ TestingProfile* profile = browser_helper_.profile(); |
+ HostContentSettingsMap* map = profile->GetHostContentSettingsMap(); |
+ HostContentSettingsMap::Pattern example_com("[*.]example.com"); |
+ map->SetContentSetting(example_com, |
+ CONTENT_SETTINGS_TYPE_PLUGINS, |
+ "blurp", |
+ CONTENT_SETTING_BLOCK); |
+ |
+ NSArrayController* controller = controller_.get(); |
+ NSArray* titles = [[controller arrangedObjects] valueForKey:@"title"]; |
+ EXPECT_NSEQ(@"(\n" |
+ @" FooPlugin,\n" |
+ @" \"[*.]example.com\",\n" |
+ @" BarPlugin,\n" |
+ @" \"[*.]example.com\",\n" |
+ @" \"[*.]moose.org\",\n" |
+ @" BlurpPlugin,\n" |
+ @" \"[*.]example.com\"\n" |
+ @")", |
+ [titles description]); |
+ NSMutableIndexSet* indexes = [NSMutableIndexSet indexSetWithIndex:1]; |
+ [indexes addIndex:6]; |
+ [controller setSelectionIndexes:indexes]; |
+ [controller remove:nil]; |
+ titles = [[controller arrangedObjects] valueForKey:@"title"]; |
+ EXPECT_NSEQ(@"(\n" |
+ @" BarPlugin,\n" |
+ @" \"[*.]example.com\",\n" |
+ @" \"[*.]moose.org\"\n" |
+ @")", |
+ [titles description]); |
+} |
+ |
+} // namespace |