Logo Search packages:      
Sourcecode: chromium-browser version File versions  Download package


// 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.


#include <string>

#include "base/command_line.h"
#include "base/file_path.h"
#include "chrome/common/notification_details.h"
#include "chrome/common/notification_observer.h"
#include "chrome/common/notification_registrar.h"
#include "chrome/common/notification_type.h"
#include "chrome/test/in_process_browser_test.h"

// Base class for extension browser tests. Provides utilities for loading,
// unloading, and installing extensions.
class ExtensionBrowserTest
    : public InProcessBrowserTest, public NotificationObserver {

  virtual void SetUpCommandLine(CommandLine* command_line);
  bool LoadExtension(const FilePath& path);

  // Same as above, but enables the extension in incognito mode first.
  bool LoadExtensionIncognito(const FilePath& path);

  // |expected_change| indicates how many extensions should be installed (or
  // disabled, if negative).
  // 1 means you expect a new install, 0 means you expect an upgrade, -1 means
  // you expect a failed upgrade.
  bool InstallExtension(const FilePath& path, int expected_change) {
    return InstallOrUpdateExtension("", path, false, expected_change);

  // Same as above but passes an id to CrxInstaller and does not allow a
  // privilege increase.
  bool UpdateExtension(const std::string& id, const FilePath& path,
                       int expected_change) {
    return InstallOrUpdateExtension(id, path, false, expected_change);

  // Begins install process but simulates a user cancel.
  bool StartInstallButCancel(const FilePath& path) {
    return InstallOrUpdateExtension("", path, true, 0);

  void ReloadExtension(const std::string& extension_id);

  void UnloadExtension(const std::string& extension_id);

  void UninstallExtension(const std::string& extension_id);

  void DisableExtension(const std::string& extension_id);

  void EnableExtension(const std::string& extension_id);

  // Wait for the total number of page actions to change to |count|.
  bool WaitForPageActionCountChangeTo(int count);

  // Wait for the number of visible page actions to change to |count|.
  bool WaitForPageActionVisibilityChangeTo(int count);

  // Waits until an extension is installed and loaded. Returns true if an
  // install happened before timeout.
  bool WaitForExtensionInstall();

  // Wait for an extension install error to be raised. Returns true if an
  // error was raised.
  bool WaitForExtensionInstallError();

  // Waits until an extension is loaded.
  void WaitForExtensionLoad();

  // Wait for the specified extension to crash. Returns true if it really
  // crashed.
  bool WaitForExtensionCrash(const std::string& extension_id);

  // NotificationObserver
  virtual void Observe(NotificationType type,
                       const NotificationSource& source,
                       const NotificationDetails& details);

  bool loaded_;
  bool installed_;

  // test_data/extensions.
  FilePath test_data_dir_;
  std::string last_loaded_extension_id_;
  int extension_installs_observed_;

  bool InstallOrUpdateExtension(const std::string& id, const FilePath& path,
                                bool should_cancel,
                                int expected_change);
  bool LoadExtensionImpl(const FilePath& path, bool incognito_enabled);

  bool WaitForExtensionHostsToLoad();

  // When waiting for page action count to change, we wait until it reaches this
  // value.
  int target_page_action_count_;

  // When waiting for visible page action count to change, we wait until it
  // reaches this value.
  int target_visible_page_action_count_;


Generated by  Doxygen 1.6.0   Back to index