This source file includes following definitions.
- ReleaseBrowserProcessModule
- CheckPreferencesSet
- CheckPreferencesCleared
- SetUpOnMainThread
- CleanUpOnMainThread
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
#include "base/prefs/pref_service.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/extensions/extension_test_message_listener.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/translate/core/common/translate_pref_names.h"
#include "content/public/browser/notification_service.h"
namespace {
void ReleaseBrowserProcessModule() {
g_browser_process->ReleaseModule();
}
}
class ExtensionPreferenceApiTest : public ExtensionApiTest {
protected:
ExtensionPreferenceApiTest() : profile_(NULL) {}
void CheckPreferencesSet() {
PrefService* prefs = profile_->GetPrefs();
const PrefService::Preference* pref = prefs->FindPreference(
prefs::kBlockThirdPartyCookies);
ASSERT_TRUE(pref);
EXPECT_TRUE(pref->IsExtensionControlled());
EXPECT_TRUE(prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled));
EXPECT_TRUE(prefs->GetBoolean(autofill::prefs::kAutofillEnabled));
EXPECT_FALSE(prefs->GetBoolean(prefs::kBlockThirdPartyCookies));
EXPECT_TRUE(prefs->GetBoolean(prefs::kEnableHyperlinkAuditing));
EXPECT_TRUE(prefs->GetBoolean(prefs::kEnableReferrers));
EXPECT_TRUE(prefs->GetBoolean(prefs::kEnableTranslate));
EXPECT_TRUE(prefs->GetBoolean(prefs::kNetworkPredictionEnabled));
EXPECT_TRUE(prefs->GetBoolean(prefs::kSafeBrowsingEnabled));
EXPECT_TRUE(prefs->GetBoolean(prefs::kSearchSuggestEnabled));
}
void CheckPreferencesCleared() {
PrefService* prefs = profile_->GetPrefs();
const PrefService::Preference* pref = prefs->FindPreference(
prefs::kBlockThirdPartyCookies);
ASSERT_TRUE(pref);
EXPECT_FALSE(pref->IsExtensionControlled());
EXPECT_FALSE(prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled));
EXPECT_FALSE(prefs->GetBoolean(autofill::prefs::kAutofillEnabled));
EXPECT_TRUE(prefs->GetBoolean(prefs::kBlockThirdPartyCookies));
EXPECT_FALSE(prefs->GetBoolean(prefs::kEnableHyperlinkAuditing));
EXPECT_FALSE(prefs->GetBoolean(prefs::kEnableReferrers));
EXPECT_FALSE(prefs->GetBoolean(prefs::kEnableTranslate));
EXPECT_FALSE(prefs->GetBoolean(prefs::kNetworkPredictionEnabled));
EXPECT_FALSE(prefs->GetBoolean(prefs::kSafeBrowsingEnabled));
EXPECT_FALSE(prefs->GetBoolean(prefs::kSearchSuggestEnabled));
}
virtual void SetUpOnMainThread() OVERRIDE {
ExtensionApiTest::SetUpOnMainThread();
profile_ = browser()->profile();
g_browser_process->AddRefModule();
}
virtual void CleanUpOnMainThread() OVERRIDE {
base::MessageLoop::current()->PostTask(
FROM_HERE, base::Bind(&ReleaseBrowserProcessModule));
content::RunAllPendingInMessageLoop();
ExtensionApiTest::CleanUpOnMainThread();
}
Profile* profile_;
};
#if defined(OS_WIN) && !defined(NDEBUG)
#define MAYBE_Standard DISABLED_Standard
#else
#define MAYBE_Standard Standard
#endif
IN_PROC_BROWSER_TEST_F(ExtensionPreferenceApiTest, MAYBE_Standard) {
PrefService* prefs = profile_->GetPrefs();
prefs->SetBoolean(prefs::kAlternateErrorPagesEnabled, false);
prefs->SetBoolean(autofill::prefs::kAutofillEnabled, false);
prefs->SetBoolean(prefs::kBlockThirdPartyCookies, true);
prefs->SetBoolean(prefs::kEnableHyperlinkAuditing, false);
prefs->SetBoolean(prefs::kEnableReferrers, false);
prefs->SetBoolean(prefs::kEnableTranslate, false);
prefs->SetBoolean(prefs::kNetworkPredictionEnabled, false);
prefs->SetBoolean(prefs::kSafeBrowsingEnabled, false);
prefs->SetBoolean(prefs::kSearchSuggestEnabled, false);
const char kExtensionPath[] = "preference/standard";
EXPECT_TRUE(RunExtensionSubtest(kExtensionPath, "test.html")) << message_;
CheckPreferencesSet();
ReloadExtension(last_loaded_extension_id());
CheckPreferencesSet();
content::WindowedNotificationObserver observer(
chrome::NOTIFICATION_EXTENSION_UNINSTALLED,
content::NotificationService::AllSources());
UninstallExtension(last_loaded_extension_id());
observer.Wait();
CheckPreferencesCleared();
LoadExtension(test_data_dir_.AppendASCII(kExtensionPath));
CheckPreferencesCleared();
}
IN_PROC_BROWSER_TEST_F(ExtensionPreferenceApiTest, PersistentIncognito) {
PrefService* prefs = profile_->GetPrefs();
prefs->SetBoolean(prefs::kBlockThirdPartyCookies, false);
EXPECT_TRUE(
RunExtensionTestIncognito("preference/persistent_incognito")) <<
message_;
EXPECT_FALSE(profile_->HasOffTheRecordProfile());
PrefService* otr_prefs = profile_->GetOffTheRecordProfile()->GetPrefs();
const PrefService::Preference* pref =
otr_prefs->FindPreference(prefs::kBlockThirdPartyCookies);
ASSERT_TRUE(pref);
EXPECT_TRUE(pref->IsExtensionControlled());
EXPECT_TRUE(otr_prefs->GetBoolean(prefs::kBlockThirdPartyCookies));
pref = prefs->FindPreference(prefs::kBlockThirdPartyCookies);
ASSERT_TRUE(pref);
EXPECT_FALSE(pref->IsExtensionControlled());
EXPECT_FALSE(prefs->GetBoolean(prefs::kBlockThirdPartyCookies));
}
IN_PROC_BROWSER_TEST_F(ExtensionPreferenceApiTest, DISABLED_IncognitoDisabled) {
EXPECT_FALSE(RunExtensionTest("preference/persistent_incognito"));
}
IN_PROC_BROWSER_TEST_F(ExtensionPreferenceApiTest, SessionOnlyIncognito) {
PrefService* prefs = profile_->GetPrefs();
prefs->SetBoolean(prefs::kBlockThirdPartyCookies, false);
EXPECT_TRUE(
RunExtensionTestIncognito("preference/session_only_incognito")) <<
message_;
EXPECT_TRUE(profile_->HasOffTheRecordProfile());
PrefService* otr_prefs = profile_->GetOffTheRecordProfile()->GetPrefs();
const PrefService::Preference* pref =
otr_prefs->FindPreference(prefs::kBlockThirdPartyCookies);
ASSERT_TRUE(pref);
EXPECT_TRUE(pref->IsExtensionControlled());
EXPECT_FALSE(otr_prefs->GetBoolean(prefs::kBlockThirdPartyCookies));
pref = prefs->FindPreference(prefs::kBlockThirdPartyCookies);
ASSERT_TRUE(pref);
EXPECT_FALSE(pref->IsExtensionControlled());
EXPECT_FALSE(prefs->GetBoolean(prefs::kBlockThirdPartyCookies));
}
IN_PROC_BROWSER_TEST_F(ExtensionPreferenceApiTest, Clear) {
PrefService* prefs = profile_->GetPrefs();
prefs->SetBoolean(prefs::kBlockThirdPartyCookies, true);
EXPECT_TRUE(RunExtensionTest("preference/clear")) << message_;
const PrefService::Preference* pref = prefs->FindPreference(
prefs::kBlockThirdPartyCookies);
ASSERT_TRUE(pref);
EXPECT_FALSE(pref->IsExtensionControlled());
EXPECT_EQ(true, prefs->GetBoolean(prefs::kBlockThirdPartyCookies));
}
IN_PROC_BROWSER_TEST_F(ExtensionPreferenceApiTest, OnChange) {
EXPECT_TRUE(RunExtensionTestIncognito("preference/onchange")) <<
message_;
}
IN_PROC_BROWSER_TEST_F(ExtensionPreferenceApiTest, OnChangeSplit) {
ResultCatcher catcher;
catcher.RestrictToProfile(profile_);
ResultCatcher catcher_incognito;
catcher_incognito.RestrictToProfile(profile_->GetOffTheRecordProfile());
ui_test_utils::OpenURLOffTheRecord(profile_, GURL("chrome://newtab/"));
ExtensionTestMessageListener listener1("changeDefault regular ready", true);
ExtensionTestMessageListener listener_incognito1(
"changeDefault incognito ready", true);
ExtensionTestMessageListener listener2(
"changeIncognitoOnly regular ready", true);
ExtensionTestMessageListener listener_incognito2(
"changeIncognitoOnly incognito ready", true);
ExtensionTestMessageListener listener3(
"changeIncognitoOnly regular listening", true);
ExtensionTestMessageListener listener_incognito3(
"changeIncognitoOnly incognito pref set", false);
ExtensionTestMessageListener listener4(
"changeDefaultOnly regular ready", true);
ExtensionTestMessageListener listener_incognito4(
"changeDefaultOnly incognito ready", true);
ExtensionTestMessageListener listener5(
"changeDefaultOnly regular pref set", false);
ExtensionTestMessageListener listener_incognito5(
"changeDefaultOnly incognito listening", true);
ExtensionTestMessageListener listener6(
"changeIncognitoOnlyBack regular ready", true);
ExtensionTestMessageListener listener_incognito6(
"changeIncognitoOnlyBack incognito ready", true);
ExtensionTestMessageListener listener7(
"changeIncognitoOnlyBack regular listening", true);
ExtensionTestMessageListener listener_incognito7(
"changeIncognitoOnlyBack incognito pref set", false);
ExtensionTestMessageListener listener8(
"clearIncognito regular ready", true);
ExtensionTestMessageListener listener_incognito8(
"clearIncognito incognito ready", true);
ExtensionTestMessageListener listener9(
"clearIncognito regular listening", true);
ExtensionTestMessageListener listener_incognito9(
"clearIncognito incognito pref cleared", false);
ExtensionTestMessageListener listener10(
"clearDefault regular ready", true);
ExtensionTestMessageListener listener_incognito10(
"clearDefault incognito ready", true);
base::FilePath extension_data_dir =
test_data_dir_.AppendASCII("preference").AppendASCII("onchange_split");
ASSERT_TRUE(LoadExtensionIncognito(extension_data_dir));
EXPECT_TRUE(listener1.WaitUntilSatisfied());
EXPECT_TRUE(listener_incognito1.WaitUntilSatisfied());
listener1.Reply("ok");
listener_incognito1.Reply("ok");
EXPECT_TRUE(listener2.WaitUntilSatisfied());
EXPECT_TRUE(listener_incognito2.WaitUntilSatisfied());
EXPECT_TRUE(listener3.WaitUntilSatisfied());
listener2.Reply("ok");
listener_incognito2.Reply("ok");
EXPECT_TRUE(listener_incognito3.WaitUntilSatisfied());
listener3.Reply("ok");
EXPECT_TRUE(listener4.WaitUntilSatisfied());
EXPECT_TRUE(listener_incognito4.WaitUntilSatisfied());
EXPECT_TRUE(listener_incognito5.WaitUntilSatisfied());
listener4.Reply("ok");
listener_incognito4.Reply("ok");
EXPECT_TRUE(listener5.WaitUntilSatisfied());
listener_incognito5.Reply("ok");
EXPECT_TRUE(listener6.WaitUntilSatisfied());
EXPECT_TRUE(listener_incognito6.WaitUntilSatisfied());
EXPECT_TRUE(listener7.WaitUntilSatisfied());
listener6.Reply("ok");
listener_incognito6.Reply("ok");
EXPECT_TRUE(listener_incognito7.WaitUntilSatisfied());
listener7.Reply("ok");
EXPECT_TRUE(listener8.WaitUntilSatisfied());
EXPECT_TRUE(listener_incognito8.WaitUntilSatisfied());
EXPECT_TRUE(listener9.WaitUntilSatisfied());
listener8.Reply("ok");
listener_incognito8.Reply("ok");
EXPECT_TRUE(listener_incognito9.WaitUntilSatisfied());
listener9.Reply("ok");
EXPECT_TRUE(listener10.WaitUntilSatisfied());
EXPECT_TRUE(listener_incognito10.WaitUntilSatisfied());
listener10.Reply("ok");
listener_incognito10.Reply("ok");
EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
EXPECT_TRUE(catcher_incognito.GetNextResult()) << catcher.message();
}