blob: 15f2e243f4cd37937d78d83f76661d92ce6beecf [file] [log] [blame]
// Copyright 2016 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 "chrome/test/base/in_process_browser_test.h"
namespace content {
class WebContents;
} // namespace content
class MockPermissionPromptFactory;
// This is a base class for end-to-end testing of features that have
// permissions. It will navigate to the URL passed in upon construction, ready
// to execute javascript to test the permissions. There are also a set of common
// test functions that are provided (see the functions with the Common* prefix).
// These should be called to ensure basic test coverage of the feature's
// permission that is being added. Custom tests can also be added for the
// permission. For an example of how to use this base class, see
// FlashPermissionBrowserTest.
class PermissionsBrowserTest : public InProcessBrowserTest {
explicit PermissionsBrowserTest(const std::string& test_url);
~PermissionsBrowserTest() override;
// InProcessBrowserTest
void SetUpOnMainThread() override;
void TearDownOnMainThread() override;
virtual void TriggerPrompt() = 0;
virtual bool FeatureUsageSucceeds() = 0;
std::string test_url() const { return test_url_; }
MockPermissionPromptFactory* prompt_factory() {
return prompt_factory_.get();
bool RunScriptReturnBool(const std::string& script);
content::WebContents* GetWebContents();
// Common tests that should be called by subclasses.
void CommonFailsBeforeRequesting();
void CommonFailsIfDismissed();
void CommonFailsIfBlocked();
void CommonSucceedsIfAllowed();
std::string test_url_;
std::unique_ptr<MockPermissionPromptFactory> prompt_factory_;