1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
// Copyright (c) 2012 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 "base/file_path.h"
#include "base/path_service.h"
#include "chrome/browser/browsing_data/browsing_data_helper.h"
#include "chrome/browser/browsing_data/browsing_data_remover.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/download_manager.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_paths.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/download_test_observer.h"
#include "content/test/net/url_request_mock_http_job.h"
#include "testing/gtest/include/gtest/gtest.h"
using content::BrowserThread;
namespace {
void SetUrlRequestMock(const FilePath& path) {
URLRequestMockHTTPJob::AddUrlHandler(path);
}
}
class BrowsingDataRemoverBrowserTest : public InProcessBrowserTest {
public:
BrowsingDataRemoverBrowserTest() {}
virtual void SetUpOnMainThread() OVERRIDE {
FilePath path;
PathService::Get(content::DIR_TEST_DATA, &path);
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE, base::Bind(&SetUrlRequestMock, path));
}
void RunScriptAndCheckResult(const std::wstring& script,
const std::string& result) {
std::string data;
ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString(
chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"",
script, &data));
ASSERT_EQ(data, result);
}
void RemoveAndWait(int remove_mask) {
content::WindowedNotificationObserver signal(
chrome::NOTIFICATION_BROWSING_DATA_REMOVED,
content::Source<Profile>(browser()->profile()));
BrowsingDataRemover* remover = BrowsingDataRemover::CreateForPeriod(
browser()->profile(), BrowsingDataRemover::LAST_HOUR);
remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
signal.Wait();
}
};
// Test BrowsingDataRemover for downloads.
IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest, Download) {
ScopedTempDir downloads_directory;
ASSERT_TRUE(downloads_directory.CreateUniqueTempDir());
browser()->profile()->GetPrefs()->SetFilePath(
prefs::kDownloadDefaultDirectory, downloads_directory.path());
// Start a download.
content::DownloadManager* download_manager =
content::BrowserContext::GetDownloadManager(browser()->profile());
scoped_ptr<content::DownloadTestObserver> observer(
new content::DownloadTestObserverTerminal(
download_manager, 1,
content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT));
GURL download_url = ui_test_utils::GetTestUrl(
FilePath().AppendASCII("downloads"),
FilePath().AppendASCII("a_zip_file.zip"));
ui_test_utils::NavigateToURL(browser(), download_url);
observer->WaitForFinished();
std::vector<content::DownloadItem*> downloads;
download_manager->GetAllDownloads(&downloads);
EXPECT_EQ(1u, downloads.size());
RemoveAndWait(BrowsingDataRemover::REMOVE_DOWNLOADS);
downloads.clear();
download_manager->GetAllDownloads(&downloads);
EXPECT_TRUE(downloads.empty());
}
// Verify can modify database after deleting it.
IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest, Database) {
GURL url(URLRequestMockHTTPJob::GetMockUrl(
FilePath().AppendASCII("simple_database.html")));
ui_test_utils::NavigateToURL(browser(), url);
RunScriptAndCheckResult(L"createTable()", "done");
RunScriptAndCheckResult(L"insertRecord('text')", "done");
RunScriptAndCheckResult(L"getRecords()", "text");
RemoveAndWait(BrowsingDataRemover::REMOVE_SITE_DATA);
ui_test_utils::NavigateToURL(browser(), url);
RunScriptAndCheckResult(L"createTable()", "done");
RunScriptAndCheckResult(L"insertRecord('text2')", "done");
RunScriptAndCheckResult(L"getRecords()", "text2");
}
|