extension_browsertest.h revision a36e5920737c6adbddd3e43b760e5de8431db6e0
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_BROWSERTEST_H_
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CHROME_BROWSER_EXTENSIONS_EXTENSION_BROWSERTEST_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string>
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/command_line.h"
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/compiler_specific.h"
122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/files/file_path.h"
132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/files/scoped_temp_dir.h"
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/extensions/extension_host.h"
152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/extensions/extension_system.h"
162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/browser.h"
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/extensions/extension.h"
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/extensions/feature_switch.h"
192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/common/extensions/features/feature.h"
202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/common/extensions/manifest.h"
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/test/base/in_process_browser_test.h"
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_details.h"
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_observer.h"
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_types.h"
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/web_contents.h"
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ExtensionProcessManager;
282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class ExtensionService;
292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class ExtensionSet;
302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class Profile;
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Base class for extension browser tests. Provides utilities for loading,
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// unloading, and installing extensions.
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ExtensionBrowserTest : virtual public InProcessBrowserTest,
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                             public content::NotificationObserver {
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected:
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Flags used to configure how the tests are run.
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  enum Flags {
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    kFlagNone = 0,
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Allow the extension to run in incognito mode.
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    kFlagEnableIncognito = 1 << 0,
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Allow file access for the extension.
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    kFlagEnableFileAccess = 1 << 1,
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Don't fail when the loaded manifest has warnings (should only be used
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // when testing deprecated features).
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    kFlagIgnoreManifestWarnings = 1 << 2,
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Allow older manifest versions (typically these can't be loaded - we allow
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // them for testing).
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    kFlagAllowOldManifestVersions = 1 << 3,
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ExtensionBrowserTest();
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~ExtensionBrowserTest();
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Useful accessors.
602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExtensionService* extension_service() {
612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return extensions::ExtensionSystem::Get(profile())->extension_service();
622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Get the profile to use.
652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  Profile* profile();
662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  static const extensions::Extension* GetExtensionByPath(
682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const ExtensionSet* extensions, const base::FilePath& path);
692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // InProcessBrowserTest
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE;
722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void SetUpOnMainThread() OVERRIDE;
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const extensions::Extension* LoadExtension(const base::FilePath& path);
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Same as above, but enables the extension in incognito mode first.
772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const extensions::Extension* LoadExtensionIncognito(
782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const base::FilePath& path);
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const extensions::Extension* LoadExtensionWithFlags(
812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const base::FilePath& path, int flags);
822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Loads unpacked extension from |path| with manifest |manifest_relative_path|
842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // and imitates that it is a component extension.
852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // |manifest_relative_path| is relative to |path|.
862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const extensions::Extension* LoadExtensionAsComponentWithManifest(
872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const base::FilePath& path,
882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const base::FilePath::CharType* manifest_relative_path);
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Loads unpacked extension from |path| and imitates that it is a component
912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // extension. Equivalent to
922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // LoadExtensionAsComponentWithManifest(path, extensions::kManifestFilename).
932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const extensions::Extension* LoadExtensionAsComponent(
942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const base::FilePath& path);
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Pack the extension in |dir_path| into a crx file and return its path.
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Return an empty FilePath if there were errors.
982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::FilePath PackExtension(const base::FilePath& dir_path);
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Pack the extension in |dir_path| into a crx file at |crx_path|, using the
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // key |pem_path|. If |pem_path| does not exist, create a new key at
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |pem_out_path|.
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Return the path to the crx file, or an empty FilePath if there were errors.
1042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::FilePath PackExtensionWithOptions(const base::FilePath& dir_path,
1052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                          const base::FilePath& crx_path,
1062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                          const base::FilePath& pem_path,
1072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                          const base::FilePath& pem_out_path);
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |expected_change| indicates how many extensions should be installed (or
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // disabled, if negative).
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // 1 means you expect a new install, 0 means you expect an upgrade, -1 means
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // you expect a failed upgrade.
1132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const extensions::Extension* InstallExtension(const base::FilePath& path,
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                                int expected_change) {
115c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return InstallOrUpdateExtension(
116c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)        std::string(), path, INSTALL_UI_TYPE_NONE, expected_change);
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Same as above, but an install source other than Manifest::INTERNAL can be
1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // specified.
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const extensions::Extension* InstallExtension(
1222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const base::FilePath& path,
1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      int expected_change,
1242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      extensions::Manifest::Location install_source) {
125c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return InstallOrUpdateExtension(std::string(),
126c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                    path,
127c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                    INSTALL_UI_TYPE_NONE,
128c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                    expected_change,
129c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                    install_source);
1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Installs extension as if it came from the Chrome Webstore.
1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const extensions::Extension* InstallExtensionFromWebstore(
1342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const base::FilePath& path, int expected_change);
1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Same as above but passes an id to CrxInstaller and does not allow a
1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // privilege increase.
1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const extensions::Extension* UpdateExtension(const std::string& id,
1392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                               const base::FilePath& path,
1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                               int expected_change) {
1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return InstallOrUpdateExtension(id, path, INSTALL_UI_TYPE_NONE,
1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                    expected_change);
1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
145a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // Same as UpdateExtension but waits for the extension to be idle first.
146a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  const extensions::Extension* UpdateExtensionWaitForIdle(
147a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      const std::string& id, const base::FilePath& path, int expected_change);
148a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Same as |InstallExtension| but with the normal extension UI showing up
1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // (for e.g. info bar on success).
1512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const extensions::Extension* InstallExtensionWithUI(
1522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const base::FilePath& path,
1532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      int expected_change) {
154c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return InstallOrUpdateExtension(
155c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)        std::string(), path, INSTALL_UI_TYPE_NORMAL, expected_change);
1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const extensions::Extension* InstallExtensionWithUIAutoConfirm(
1592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const base::FilePath& path,
1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      int expected_change,
1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      Browser* browser) {
162c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return InstallOrUpdateExtension(std::string(),
163c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                    path,
164c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                    INSTALL_UI_TYPE_AUTO_CONFIRM,
165c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                    expected_change,
166c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                    browser,
167c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                    false);
1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Begins install process but simulates a user cancel.
1712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const extensions::Extension* StartInstallButCancel(
1722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const base::FilePath& path) {
173c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return InstallOrUpdateExtension(
174c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)        std::string(), path, INSTALL_UI_TYPE_CANCEL, 0);
1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
177eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  void ReloadExtension(const std::string extension_id);
1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void UnloadExtension(const std::string& extension_id);
1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void UninstallExtension(const std::string& extension_id);
1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void DisableExtension(const std::string& extension_id);
1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void EnableExtension(const std::string& extension_id);
1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Wait for the total number of page actions to change to |count|.
1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool WaitForPageActionCountChangeTo(int count);
1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Wait for the number of visible page actions to change to |count|.
1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool WaitForPageActionVisibilityChangeTo(int count);
1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Waits until an extension is installed and loaded. Returns true if an
1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // install happened before timeout.
1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool WaitForExtensionInstall();
1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Wait for an extension install error to be raised. Returns true if an
1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // error was raised.
1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool WaitForExtensionInstallError();
2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Waits until an extension is loaded.
2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void WaitForExtensionLoad();
2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Waits for an extension load error. Returns true if the error really
2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // happened.
2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool WaitForExtensionLoadError();
2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Wait for the specified extension to crash. Returns true if it really
2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // crashed.
2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool WaitForExtensionCrash(const std::string& extension_id);
2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Wait for the crx installer to be done. Returns true if it really is done.
2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool WaitForCrxInstallerDone();
2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Simulates a page calling window.open on an URL and waits for the
2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // navigation.
2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void OpenWindow(content::WebContents* contents,
2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                  const GURL& url,
2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                  bool newtab_process_should_equal_opener,
2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                  content::WebContents** newtab_result);
2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Simulates a page navigating itself to an URL and waits for the
2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // navigation.
2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void NavigateInRenderer(content::WebContents* contents, const GURL& url);
2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Looks for an ExtensionHost whose URL has the given path component
2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // (including leading slash).  Also verifies that the expected number of hosts
2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // are loaded.
2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  extensions::ExtensionHost* FindHostWithPath(ExtensionProcessManager* manager,
2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                              const std::string& path,
2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                              int expected_hosts);
2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // content::NotificationObserver
2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void Observe(int type,
2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                       const content::NotificationSource& source,
2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                       const content::NotificationDetails& details) OVERRIDE;
2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool loaded_;
2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool installed_;
2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // test_data/extensions.
2422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::FilePath test_data_dir_;
2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::string last_loaded_extension_id_;
2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int extension_installs_observed_;
2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int extension_load_errors_observed_;
2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int crx_installers_done_observed_;
2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Temporary directory for testing.
2502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::ScopedTempDir temp_dir_;
2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Specifies the type of UI (if any) to show during installation and what
2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // user action to simulate.
2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  enum InstallUIType {
2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    INSTALL_UI_TYPE_NONE,
2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    INSTALL_UI_TYPE_CANCEL,
2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    INSTALL_UI_TYPE_NORMAL,
2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    INSTALL_UI_TYPE_AUTO_CONFIRM,
2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const extensions::Extension* InstallOrUpdateExtension(
2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const std::string& id,
2632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const base::FilePath& path,
2642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      InstallUIType ui_type,
2652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      int expected_change);
2662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const extensions::Extension* InstallOrUpdateExtension(
2672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const std::string& id,
2682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const base::FilePath& path,
2692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      InstallUIType ui_type,
2702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      int expected_change,
2712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      Browser* browser,
2722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      bool from_webstore);
2732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const extensions::Extension* InstallOrUpdateExtension(
2742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const std::string& id,
2752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const base::FilePath& path,
2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      InstallUIType ui_type,
2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      int expected_change,
2782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      extensions::Manifest::Location install_source);
2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const extensions::Extension* InstallOrUpdateExtension(
2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const std::string& id,
2812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const base::FilePath& path,
2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      InstallUIType ui_type,
2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      int expected_change,
2842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      extensions::Manifest::Location install_source,
2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      Browser* browser,
286a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      bool from_webstore,
287a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      bool wait_for_idle);
2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool WaitForExtensionViewsToLoad();
2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // When waiting for page action count to change, we wait until it reaches this
2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // value.
2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int target_page_action_count_;
2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // When waiting for visible page action count to change, we wait until it
2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // reaches this value.
2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int target_visible_page_action_count_;
2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Make the current channel "dev" for the duration of the test.
3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  extensions::Feature::ScopedCurrentChannel current_channel_;
3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Disable external install UI.
3035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  extensions::FeatureSwitch::ScopedOverride
3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      override_prompt_for_external_extensions_;
3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // The default profile to be used.
3072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  Profile* profile_;
3085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
3095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // CHROME_BROWSER_EXTENSIONS_EXTENSION_BROWSERTEST_H_
311