Index: chrome/test/data/extensions/activity_log/ad_injection/content_script.js |
diff --git a/chrome/test/data/extensions/activity_log/ad_injection/content_script.js b/chrome/test/data/extensions/activity_log/ad_injection/content_script.js |
index 2e6130232f6dd80d9c55e475041a5b9fbdabcb43..fe5ca201b68ded328468e5189d1462b4e8a8727f 100644 |
--- a/chrome/test/data/extensions/activity_log/ad_injection/content_script.js |
+++ b/chrome/test/data/extensions/activity_log/ad_injection/content_script.js |
@@ -33,12 +33,10 @@ var kBodyHtml = |
'<iframe id="non-ad-iframe" src="http://www.not-ads.adnetwork"></iframe>' + |
'<embed id="ad-embed" src="http://www.known-ads.adnetwork"><embed>' + |
'<embed id="non-ad-embed" src="http://www.not-ads.adnetwork"><embed>' + |
- '<a id="ad-link" href="http://www.known-ads.adnetwork"></a>' + |
- '<a id="non-ad-link" href="http://www.not-ads.adnetwork"></a>' + |
+ '<a id="ad-anchor" href="http://www.known-ads.adnetwork"></a>' + |
+ '<a id="non-ad-anchor" href="http://www.not-ads.adnetwork"></a>' + |
'<div id="empty-div"></div>'; |
- |
- |
/** |
* The AdInjectorTest infrastructure. Basically, this allows the test to follow |
* a simple iteration cycle: |
@@ -136,13 +134,20 @@ AdInjectorTest.prototype = { |
// what kind of injection. |
// These match the enum values in |
// chrome/browser/extensions/activity_log/activity_actions.h. |
-var NO_AD_INJECTION = 0; // The signal that there was no ad injection. |
-var INJECTION_NEW_AD = 1; // The signal that there was a new ad injected. |
-var INJECTION_REMOVED_AD = 2; // The signal that an ad was removed. |
-var INJECTION_REPLACED_AD = 3; // The signal that an ad was replaced. |
+// The signal that there was no ad injection. |
+var NO_AD_INJECTION = 0; |
+// The signal that there was a new ad injected. |
+var INJECTION_NEW_AD = 1; |
+// The signal that an ad was removed. |
+var INJECTION_REMOVED_AD = 2; |
+// The signal that an ad was replaced. |
+var INJECTION_REPLACED_AD = 3; |
+// The signal that an ad was likely replaced, but we didn't detect it fully. |
+var INJECTION_LIKELY_REPLACED_AD = 4; |
/* The "ad network" url to use for tests. */ |
var kAdNetwork = 'http://www.known-ads.adnetwork'; |
+var kAdNetwork2 = 'http://www.also-known-ads.adnetwork'; |
/* The "non ad network" url to use for tests. */ |
var kNonAdNetwork = 'http://www.not-ads.adnetwork'; |
@@ -185,16 +190,17 @@ var getEmbedAd = function() { |
return kEmbedAdTemplate.cloneNode(true); |
}; |
-// Creates a link ad, like so: |
+// Creates an anchor ad, like so: |
// <a href="http://www.known-ads.adnetwork"></a> |
-var kLinkAdTemplate = document.createElement('a'); |
-kLinkAdTemplate.href = kAdNetwork; |
+var kAnchorAdTemplate = document.createElement('a'); |
+kAnchorAdTemplate.href = kAdNetwork; |
/** |
- * @return A link ('a') element which will count as ad injection in the tests. |
+ * @return An anchor ('a') element which will count as ad injection in the |
+ * tests. |
*/ |
-var getLinkAd = function() { |
- return kLinkAdTemplate.cloneNode(true); |
+var getAnchorAd = function() { |
+ return kAnchorAdTemplate.cloneNode(true); |
}; |
// This series constructs a nested ad, which looks like this: |
@@ -246,7 +252,7 @@ functions.push(function NewIframeNonAdNetwork() { |
// Modify an iframe which is currently in the DOM, switching the src to an |
// ad network. |
functions.push(function ModifyExistingIframeToAdNetwork() { |
- var frame = $('ad-iframe'); |
+ var frame = $('non-ad-iframe'); |
frame.src = kAdNetwork; |
return INJECTION_NEW_AD; |
}); |
@@ -269,14 +275,27 @@ functions.push(function NewEmbedNonAdNetwork() { |
// Modify an embed which is currently in the DOM, switching the src to an |
// ad network. |
functions.push(function ModifyExistingEmbedToAdNetwork() { |
- var embed = $('ad-embed'); |
+ var embed = $('non-ad-embed'); |
embed.src = kAdNetwork; |
return INJECTION_NEW_AD; |
}); |
-// Add a new link element which serves ads. |
-functions.push(function NewLinkAd() { |
- document.body.appendChild(getLinkAd()); |
+// Add a new anchor element which serves ads. |
+functions.push(function NewAnchorAd() { |
+ document.body.appendChild(getAnchorAd()); |
+ return INJECTION_NEW_AD; |
+}); |
+ |
+functions.push(function NewAnchorNonAd() { |
+ var anchor = document.createElement('a'); |
+ anchor.src = kNonAdNetwork; |
+ document.body.appendChild(anchor); |
+ return NO_AD_INJECTION; |
+}); |
+ |
+functions.push(function ModifyExistingAnchorToAdNetwork() { |
+ var anchor = $('non-ad-anchor'); |
+ anchor.href = kAdNetwork; |
return INJECTION_NEW_AD; |
}); |
@@ -287,6 +306,40 @@ functions.push(function NewNestedAd() { |
return INJECTION_NEW_AD; |
}); |
+// Switch an existing embed ad to a new ad network. |
+functions.push(function ReplaceEmbedAd() { |
+ $('ad-embed').src = kAdNetwork2; |
+ return INJECTION_REPLACED_AD; |
+}); |
+ |
+// Switch an existing iframe ad to a new ad network. |
+functions.push(function ReplaceIframeAd() { |
+ $('ad-iframe').src = kAdNetwork2; |
+ return INJECTION_REPLACED_AD; |
+}); |
+ |
+// Switch an existing anchor ad to a new ad network. |
+functions.push(function ReplaceAnchorAd() { |
+ $('ad-anchor').href = kAdNetwork2; |
+ return INJECTION_REPLACED_AD; |
+}); |
+ |
+// Remove an existing embed ad by setting it's src to a non-ad network. |
+functions.push(function RemoveAdBySettingSrc() { |
+ $('ad-embed').src = kNonAdNetwork; |
+ return INJECTION_REMOVED_AD; |
+}); |
+ |
+// Ensure that we flag actions that look a lot like ad injection, even if we're |
+// not sure. |
+functions.push(function LikelyAdInjection() { |
+ // Switching from one valid url src to another valid url src is very |
+ // suspicious behavior, and should be relatively rare. This helps us determine |
+ // the effectiveness of our ad network recognition. |
+ $('non-ad-embed').src = 'http://www.thismightbeanadnetwork.ads'; |
+ return INJECTION_LIKELY_REPLACED_AD; |
+}); |
+ |
// Verify that we do not enter the javascript world when we check for ad |
// injection. |
functions.push(function VerifyNoAccess() { |