Commit e0c6a8d0 authored by mvrable@chromium.org's avatar mvrable@chromium.org

[Activity log] Rework extraction of URLs from argument lists

Redo the code for handling the tabs API and tab ID translation to make
it more generic.  Make it table driven: there is now a table of API
calls that can contain URL arguments, so it is easy to add additional
API calls that we want to have URLs extracted from.  Add a couple of
others I've come across in testing.

BUG=253368, 275701

Review URL: https://chromiumcodereview.appspot.com/23545012

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@222155 0039d316-1c4b-4281-b951-d872f2087c98
parent 33c1f539
...@@ -21,4 +21,8 @@ const char kActionWebRequest[] = "web_request"; ...@@ -21,4 +21,8 @@ const char kActionWebRequest[] = "web_request";
// recording specific data about the pages. // recording specific data about the pages.
const char kIncognitoUrl[] = "<incognito>"; const char kIncognitoUrl[] = "<incognito>";
// A string used as a placeholder for URLs which have been removed from the
// argument list and stored to the arg_url field.
const char kArgUrlPlaceholder[] = "<arg_url>";
} // namespace activity_log_constants } // namespace activity_log_constants
...@@ -22,6 +22,10 @@ extern const char kActionWebRequest[]; ...@@ -22,6 +22,10 @@ extern const char kActionWebRequest[];
// recording specific data about the pages. // recording specific data about the pages.
extern const char kIncognitoUrl[]; extern const char kIncognitoUrl[];
// A string used as a placeholder for URLs which have been removed from the
// argument list and stored to the arg_url field.
extern const char kArgUrlPlaceholder[];
} // namespace activity_log_constants } // namespace activity_log_constants
#endif // CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_ACTION_CONSTANTS_H_ #endif // CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_ACTION_CONSTANTS_H_
...@@ -103,6 +103,20 @@ class ActivityLogTest : public ChromeRenderViewHostTestHarness { ...@@ -103,6 +103,20 @@ class ActivityLogTest : public ChromeRenderViewHostTestHarness {
ASSERT_EQ("", last->SerializeArgUrl()); ASSERT_EQ("", last->SerializeArgUrl());
} }
static void RetrieveActions_ArgUrlExtraction(
scoped_ptr<std::vector<scoped_refptr<Action> > > i) {
ASSERT_EQ(2U, i->size());
scoped_refptr<Action> action = i->at(0);
ASSERT_EQ("[\"GET\",\"\\u003Carg_url\\u003E\"]",
ActivityLogPolicy::Util::Serialize(action->args()));
ASSERT_EQ("http://www.google.com/", action->arg_url().spec());
action = i->at(1);
ASSERT_EQ("[{\"url\":\"\\u003Carg_url\\u003E\"}]",
ActivityLogPolicy::Util::Serialize(action->args()));
ASSERT_EQ("http://www.google.co.uk/", action->arg_url().spec());
}
ExtensionService* extension_service_; ExtensionService* extension_service_;
#if defined OS_CHROMEOS #if defined OS_CHROMEOS
...@@ -193,4 +207,41 @@ TEST_F(ActivityLogTest, LogPrerender) { ...@@ -193,4 +207,41 @@ TEST_F(ActivityLogTest, LogPrerender) {
prerender_manager->CancelAllPrerenders(); prerender_manager->CancelAllPrerenders();
} }
TEST_F(ActivityLogTest, ArgUrlExtraction) {
ActivityLog* activity_log = ActivityLog::GetInstance(profile());
scoped_ptr<base::ListValue> args(new base::ListValue());
base::Time now = base::Time::Now();
// Submit a DOM API call which should have its URL extracted into the arg_url
// field.
scoped_refptr<Action> action = new Action(kExtensionId,
now,
Action::ACTION_DOM_ACCESS,
"XMLHttpRequest.open");
action->mutable_args()->AppendString("GET");
action->mutable_args()->AppendString("http://www.google.com/");
activity_log->LogAction(action);
// Submit an API call with an embedded URL.
action = new Action(kExtensionId,
now - base::TimeDelta::FromSeconds(1),
Action::ACTION_API_CALL,
"windows.create");
action->set_args(
ListBuilder()
.Append(DictionaryBuilder().Set("url", "http://www.google.co.uk"))
.Build());
activity_log->LogAction(action);
activity_log->GetFilteredActions(
kExtensionId,
Action::ACTION_ANY,
"",
"",
"",
0,
base::Bind(ActivityLogTest::RetrieveActions_ArgUrlExtraction));
}
} // namespace extensions } // namespace extensions
...@@ -396,9 +396,14 @@ chrome.activityLogPrivate.onExtensionActivity.addListener( ...@@ -396,9 +396,14 @@ chrome.activityLogPrivate.onExtensionActivity.addListener(
console.log('Logged:' + apiCall + ' Expected:' + expectedCall); console.log('Logged:' + apiCall + ' Expected:' + expectedCall);
chrome.test.assertEq(expectedCall, apiCall); chrome.test.assertEq(expectedCall, apiCall);
// Check that no real URLs are logged in incognito-mode tests. // Check that no real URLs are logged in incognito-mode tests. Ignore
checkIncognito(activity['pageUrl'], testCases[testCaseIndx].is_incognito); // the initial call to windows.create opening the tab.
checkIncognito(activity['argUrl'], testCases[testCaseIndx].is_incognito); if (apiCall != 'windows.create') {
checkIncognito(activity['pageUrl'],
testCases[testCaseIndx].is_incognito);
checkIncognito(activity['argUrl'],
testCases[testCaseIndx].is_incognito);
}
// If all the expected calls have been logged for this test case then // If all the expected calls have been logged for this test case then
// mark as suceeded and move to the next. Otherwise look for the next // mark as suceeded and move to the next. Otherwise look for the next
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment