| 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 #import "chrome/browser/cocoa/simple_content_exceptions_window_controller.h" | 5 #import "chrome/browser/cocoa/simple_content_exceptions_window_controller.h" | 
| 6 | 6 | 
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> | 
| 8 | 8 | 
| 9 #import "base/scoped_nsobject.h" | 9 #import "base/scoped_nsobject.h" | 
| 10 #include "base/ref_counted.h" | 10 #include "base/ref_counted.h" | 
| 11 #include "chrome/browser/cocoa/browser_test_helper.h" | 11 #include "chrome/browser/cocoa/browser_test_helper.h" | 
| 12 #include "chrome/browser/cocoa/cocoa_test_helper.h" | 12 #include "chrome/browser/cocoa/cocoa_test_helper.h" | 
| 13 #include "chrome/browser/geolocation/geolocation_exceptions_table_model.h" | 13 #include "chrome/browser/geolocation/geolocation_exceptions_table_model.h" | 
|  | 14 #include "chrome/browser/host_content_settings_map.h" | 
|  | 15 #include "chrome/browser/plugin_exceptions_table_model.h" | 
| 14 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" | 
| 15 #include "testing/platform_test.h" | 17 #include "testing/platform_test.h" | 
| 16 | 18 | 
|  | 19 @interface SimpleContentExceptionsWindowController (Testing) | 
|  | 20 | 
|  | 21 @property(readonly, nonatomic) TableModelArrayController* arrayController; | 
|  | 22 | 
|  | 23 @end | 
|  | 24 | 
|  | 25 @implementation SimpleContentExceptionsWindowController (Testing) | 
|  | 26 | 
|  | 27 - (TableModelArrayController*)arrayController { | 
|  | 28   return arrayController_; | 
|  | 29 } | 
|  | 30 | 
|  | 31 @end | 
|  | 32 | 
|  | 33 | 
| 17 namespace { | 34 namespace { | 
| 18 | 35 | 
| 19 class SimpleContentExceptionsWindowControllerTest : public CocoaTest { | 36 class SimpleContentExceptionsWindowControllerTest : public CocoaTest { | 
| 20  public: | 37  public: | 
| 21   virtual void SetUp() { | 38   virtual void SetUp() { | 
| 22     CocoaTest::SetUp(); | 39     CocoaTest::SetUp(); | 
| 23     TestingProfile* profile = browser_helper_.profile(); | 40     TestingProfile* profile = browser_helper_.profile(); | 
| 24     settingsMap_ = new GeolocationContentSettingsMap(profile); | 41     geolocation_settings_ = new GeolocationContentSettingsMap(profile); | 
|  | 42     content_settings_ = new HostContentSettingsMap(profile); | 
| 25   } | 43   } | 
| 26 | 44 | 
| 27   SimpleContentExceptionsWindowController* GetController() { | 45   SimpleContentExceptionsWindowController* GetController() { | 
| 28   GeolocationExceptionsTableModel* model =  // Freed by window controller. | 46     GeolocationExceptionsTableModel* model =  // Freed by window controller. | 
| 29       new GeolocationExceptionsTableModel(settingsMap_.get()); | 47         new GeolocationExceptionsTableModel(geolocation_settings_.get()); | 
| 30     id controller = [SimpleContentExceptionsWindowController | 48     id controller = [SimpleContentExceptionsWindowController | 
| 31         controllerWithTableModel:model]; | 49         controllerWithTableModel:model]; | 
| 32     [controller showWindow:nil]; | 50     [controller showWindow:nil]; | 
| 33     return controller; | 51     return controller; | 
| 34   } | 52   } | 
| 35 | 53 | 
| 36   void ClickRemoveAll(SimpleContentExceptionsWindowController* controller) { | 54   void ClickRemoveAll(SimpleContentExceptionsWindowController* controller) { | 
| 37     [controller removeAll:nil]; | 55     [controller.arrayController removeAll:nil]; | 
| 38   } | 56   } | 
| 39 | 57 | 
| 40  protected: | 58  protected: | 
| 41   BrowserTestHelper browser_helper_; | 59   BrowserTestHelper browser_helper_; | 
| 42   scoped_refptr<GeolocationContentSettingsMap> settingsMap_; | 60   scoped_refptr<GeolocationContentSettingsMap> geolocation_settings_; | 
|  | 61   scoped_refptr<HostContentSettingsMap> content_settings_; | 
| 43 }; | 62 }; | 
| 44 | 63 | 
| 45 TEST_F(SimpleContentExceptionsWindowControllerTest, Construction) { | 64 TEST_F(SimpleContentExceptionsWindowControllerTest, Construction) { | 
| 46   GeolocationExceptionsTableModel* model =  // Freed by window controller. | 65   GeolocationExceptionsTableModel* model =  // Freed by window controller. | 
| 47       new GeolocationExceptionsTableModel(settingsMap_.get()); | 66       new GeolocationExceptionsTableModel(geolocation_settings_.get()); | 
| 48   SimpleContentExceptionsWindowController* controller = | 67   SimpleContentExceptionsWindowController* controller = | 
| 49       [SimpleContentExceptionsWindowController controllerWithTableModel:model]; | 68       [SimpleContentExceptionsWindowController controllerWithTableModel:model]; | 
| 50   [controller showWindow:nil]; | 69   [controller showWindow:nil]; | 
|  | 70   [controller close];  // Should autorelease. | 
|  | 71 } | 
|  | 72 | 
|  | 73 TEST_F(SimpleContentExceptionsWindowControllerTest, ShowPluginExceptions) { | 
|  | 74   PluginExceptionsTableModel* model =  // Freed by window controller. | 
|  | 75       new PluginExceptionsTableModel(content_settings_.get(), NULL); | 
|  | 76   SimpleContentExceptionsWindowController* controller = | 
|  | 77       [SimpleContentExceptionsWindowController controllerWithTableModel:model]; | 
|  | 78   [controller showWindow:nil]; | 
| 51   [controller close];  // Should autorelease. | 79   [controller close];  // Should autorelease. | 
| 52 } | 80 } | 
| 53 | 81 | 
| 54 TEST_F(SimpleContentExceptionsWindowControllerTest, AddExistingEditAdd) { | 82 TEST_F(SimpleContentExceptionsWindowControllerTest, AddExistingEditAdd) { | 
| 55   settingsMap_->SetContentSetting( | 83   geolocation_settings_->SetContentSetting( | 
| 56       GURL("http://myhost"), GURL(), CONTENT_SETTING_BLOCK); | 84       GURL("http://myhost"), GURL(), CONTENT_SETTING_BLOCK); | 
| 57 | 85 | 
| 58   SimpleContentExceptionsWindowController* controller = GetController(); | 86   SimpleContentExceptionsWindowController* controller = GetController(); | 
| 59   ClickRemoveAll(controller); | 87   ClickRemoveAll(controller); | 
| 60 | 88 | 
| 61   [controller close]; | 89   [controller close]; | 
| 62 | 90 | 
| 63   EXPECT_EQ(0u, settingsMap_->GetAllOriginsSettings().size()); | 91   EXPECT_EQ(0u, geolocation_settings_->GetAllOriginsSettings().size()); | 
| 64 } | 92 } | 
| 65 | 93 | 
| 66 }  // namespace | 94 }  // namespace | 
| OLD | NEW | 
|---|