Home | History | Annotate | Download | only in extensions
      1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "base/memory/scoped_nsobject.h"
      6 #include "base/message_loop.h"
      7 #include "chrome/browser/extensions/extension_pref_value_map.h"
      8 #include "chrome/browser/extensions/extension_prefs.h"
      9 #include "chrome/browser/extensions/extension_process_manager.h"
     10 #include "chrome/browser/extensions/extension_service.h"
     11 #include "chrome/browser/ui/cocoa/browser_test_helper.h"
     12 #include "chrome/browser/ui/cocoa/cocoa_test_helper.h"
     13 #include "chrome/browser/ui/cocoa/extensions/extension_popup_controller.h"
     14 #include "chrome/test/testing_profile.h"
     15 
     16 namespace {
     17 
     18 class ExtensionTestingProfile : public TestingProfile {
     19  public:
     20   ExtensionTestingProfile() {}
     21 
     22   FilePath GetExtensionsInstallDir() {
     23     return GetPath().AppendASCII(ExtensionService::kInstallDirectoryName);
     24   }
     25 
     26   void InitExtensionProfile() {
     27     DCHECK(!GetExtensionProcessManager());
     28     DCHECK(!GetExtensionService());
     29 
     30     manager_.reset(ExtensionProcessManager::Create(this));
     31     extension_pref_value_map_.reset(new ExtensionPrefValueMap);
     32     extension_prefs_.reset(new ExtensionPrefs(GetPrefs(),
     33                                               GetExtensionsInstallDir(),
     34                                               extension_pref_value_map_.get()));
     35     service_ = new ExtensionService(this,
     36                                      CommandLine::ForCurrentProcess(),
     37                                      GetExtensionsInstallDir(),
     38                                      extension_prefs_.get(),
     39                                      false,
     40                                      true);
     41     service_->set_extensions_enabled(true);
     42     service_->set_show_extensions_prompts(false);
     43     service_->ClearProvidersForTesting();
     44     service_->Init();
     45   }
     46 
     47   void ShutdownExtensionProfile() {
     48     manager_.reset();
     49     service_ = NULL;
     50     extension_prefs_.reset();
     51   }
     52 
     53   virtual ExtensionProcessManager* GetExtensionProcessManager() {
     54     return manager_.get();
     55   }
     56 
     57   virtual ExtensionService* GetExtensionService() {
     58     return service_.get();
     59   }
     60 
     61  private:
     62   scoped_ptr<ExtensionProcessManager> manager_;
     63   scoped_ptr<ExtensionPrefs> extension_prefs_;
     64   scoped_refptr<ExtensionService> service_;
     65   scoped_ptr<ExtensionPrefValueMap> extension_pref_value_map_;
     66 
     67   DISALLOW_COPY_AND_ASSIGN(ExtensionTestingProfile);
     68 };
     69 
     70 class ExtensionPopupControllerTest : public CocoaTest {
     71  public:
     72   virtual void SetUp() {
     73     CocoaTest::SetUp();
     74     profile_.reset(new ExtensionTestingProfile());
     75     profile_->InitExtensionProfile();
     76     browser_.reset(new Browser(Browser::TYPE_NORMAL, profile_.get()));
     77     [ExtensionPopupController showURL:GURL("http://google.com")
     78                             inBrowser:browser_.get()
     79                            anchoredAt:NSZeroPoint
     80                         arrowLocation:info_bubble::kTopRight
     81                               devMode:NO];
     82   }
     83   virtual void TearDown() {
     84     profile_->ShutdownExtensionProfile();
     85     [[ExtensionPopupController popup] close];
     86     CocoaTest::TearDown();
     87   }
     88 
     89  protected:
     90   scoped_ptr<Browser> browser_;
     91   scoped_ptr<ExtensionTestingProfile> profile_;
     92 };
     93 
     94 TEST_F(ExtensionPopupControllerTest, DISABLED_Basics) {
     95   // TODO(andybons): Better mechanisms for mocking out the extensions service
     96   // and extensions for easy testing need to be implemented.
     97   // http://crbug.com/28316
     98   EXPECT_TRUE([ExtensionPopupController popup]);
     99 }
    100 
    101 }  // namespace
    102