Skip to content
This repository has been archived by the owner on Aug 5, 2020. It is now read-only.

Commit

Permalink
Comment, refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Roman Rudenko committed Mar 25, 2013
1 parent a8b5cae commit 9c6eb30
Show file tree
Hide file tree
Showing 67 changed files with 150 additions and 86 deletions.
56 changes: 28 additions & 28 deletions test/fixtures-integration-tag/7firstload.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,43 @@
<html>
<head>
<title>title</title>
<!-- This test should run in a completely clean environment, forcing the tag to synchronously load detector.js to decide if capturing is needed or not -->
</head>
<body>
<script src="/filler/comradeLaikaRocketDog00.js"></script>
<img src="/filler/comradeLaikaRocketDog01.jpg">
<iframe src="/filler/comradeLaikaRocketDog02.jpg"></iframe>
<script src="/filler/sample.js?0"></script>
<img src="/filler/sample.jpg?0">
<iframe src="/filler/sample2.jpg?0"></iframe>

<script src="/filler/comradeLaikaRocketDog03.js"></script>
<img src="/filler/comradeLaikaRocketDog04.jpg">
<iframe src="/filler/comradeLaikaRocketDog05.jpg"></iframe>
<script src="/filler/sample.js?1"></script>
<img src="/filler/sample.jpg?1">
<iframe src="/filler/sample2.jpg?1"></iframe>

<script src="/filler/comradeLaikaRocketDog06.js"></script>
<img src="/filler/comradeLaikaRocketDog07.jpg">
<iframe src="/filler/comradeLaikaRocketDog08.jpg"></iframe>
<script src="/filler/sample.js?2"></script>
<img src="/filler/sample.jpg?2">
<iframe src="/filler/sample2.jpg?2"></iframe>

<script src="/filler/sample.js?3"></script>
<img src="/filler/sample.jpg?3">
<iframe src="/filler/sample2.jpg?3"></iframe>

<script src="/filler/comradeLaikaRocketDog10.js"></script>
<img src="/filler/comradeLaikaRocketDog11.jpg">
<iframe src="/filler/comradeLaikaRocketDog12.jpg"></iframe>
<script src="/filler/sample.js?4"></script>
<img src="/filler/sample.jpg?4">
<iframe src="/filler/sample2.jpg?4"></iframe>

<script src="/filler/comradeLaikaRocketDog13.js"></script>
<img src="/filler/comradeLaikaRocketDog14.jpg">
<iframe src="/filler/comradeLaikaRocketDog15.jpg"></iframe>
<script src="/filler/sample.js?5"></script>
<img src="/filler/sample.jpg?5">
<iframe src="/filler/sample2.jpg?5"></iframe>

<script src="/filler/comradeLaikaRocketDog16.js"></script>
<img src="/filler/comradeLaikaRocketDog17.jpg">
<iframe src="/filler/comradeLaikaRocketDog18.jpg"></iframe>
<script src="/filler/sample.js?6"></script>
<img src="/filler/sample.jpg?6">
<iframe src="/filler/sample2.jpg?6"></iframe>

<script src="/filler/comradeLaikaRocketDog20.js"></script>
<img src="/filler/comradeLaikaRocketDog21.jpg">
<iframe src="/filler/comradeLaikaRocketDog22.jpg"></iframe>
<script src="/filler/sample.js?7"></script>
<img src="/filler/sample.jpg?7">
<iframe src="/filler/sample2.jpg?7"></iframe>

<script src="/filler/comradeLaikaRocketDog23.js"></script>
<img src="/filler/comradeLaikaRocketDog24.jpg">
<iframe src="/filler/comradeLaikaRocketDog25.jpg"></iframe>

<script src="/filler/comradeLaikaRocketDog26.js"></script>
<img src="/filler/comradeLaikaRocketDog27.jpg">
<iframe src="/filler/comradeLaikaRocketDog28.jpg"></iframe>
<script src="/filler/sample.js?8"></script>
<img src="/filler/sample.jpg?8">
<iframe src="/filler/sample2.jpg?8"></iframe>
</body>
</head>
56 changes: 28 additions & 28 deletions test/fixtures-integration-tag/7secondload.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,43 @@
<html>
<head>
<title>title</title>
<!-- This test should run after detection has been completed, and depends on cookie being set in 7firstload.html detector.js invocation. Thanks to cookie being set, there should be no leakage on handsets -->
</head>
<body>
<script src="/filler/comradeLaikaRocketDog00.js"></script>
<img src="/filler/comradeLaikaRocketDog01.jpg">
<iframe src="/filler/comradeLaikaRocketDog02.jpg"></iframe>
<script src="/filler/sample.js?0"></script>
<img src="/filler/sample.jpg?0">
<iframe src="/filler/sample2.jpg?0"></iframe>

<script src="/filler/comradeLaikaRocketDog03.js"></script>
<img src="/filler/comradeLaikaRocketDog04.jpg">
<iframe src="/filler/comradeLaikaRocketDog05.jpg"></iframe>
<script src="/filler/sample.js?1"></script>
<img src="/filler/sample.jpg?1">
<iframe src="/filler/sample2.jpg?1"></iframe>

<script src="/filler/comradeLaikaRocketDog06.js"></script>
<img src="/filler/comradeLaikaRocketDog07.jpg">
<iframe src="/filler/comradeLaikaRocketDog08.jpg"></iframe>
<script src="/filler/sample.js?2"></script>
<img src="/filler/sample.jpg?2">
<iframe src="/filler/sample2.jpg?2"></iframe>

<script src="/filler/sample.js?3"></script>
<img src="/filler/sample.jpg?3">
<iframe src="/filler/sample2.jpg?3"></iframe>

<script src="/filler/comradeLaikaRocketDog10.js"></script>
<img src="/filler/comradeLaikaRocketDog11.jpg">
<iframe src="/filler/comradeLaikaRocketDog12.jpg"></iframe>
<script src="/filler/sample.js?4"></script>
<img src="/filler/sample.jpg?4">
<iframe src="/filler/sample2.jpg?4"></iframe>

<script src="/filler/comradeLaikaRocketDog13.js"></script>
<img src="/filler/comradeLaikaRocketDog14.jpg">
<iframe src="/filler/comradeLaikaRocketDog15.jpg"></iframe>
<script src="/filler/sample.js?5"></script>
<img src="/filler/sample.jpg?5">
<iframe src="/filler/sample2.jpg?5"></iframe>

<script src="/filler/comradeLaikaRocketDog16.js"></script>
<img src="/filler/comradeLaikaRocketDog17.jpg">
<iframe src="/filler/comradeLaikaRocketDog18.jpg"></iframe>
<script src="/filler/sample.js?6"></script>
<img src="/filler/sample.jpg?6">
<iframe src="/filler/sample2.jpg?6"></iframe>

<script src="/filler/comradeLaikaRocketDog20.js"></script>
<img src="/filler/comradeLaikaRocketDog21.jpg">
<iframe src="/filler/comradeLaikaRocketDog22.jpg"></iframe>
<script src="/filler/sample.js?7"></script>
<img src="/filler/sample.jpg?7">
<iframe src="/filler/sample2.jpg?7"></iframe>

<script src="/filler/comradeLaikaRocketDog23.js"></script>
<img src="/filler/comradeLaikaRocketDog24.jpg">
<iframe src="/filler/comradeLaikaRocketDog25.jpg"></iframe>

<script src="/filler/comradeLaikaRocketDog26.js"></script>
<img src="/filler/comradeLaikaRocketDog27.jpg">
<iframe src="/filler/comradeLaikaRocketDog28.jpg"></iframe>
<script src="/filler/sample.js?8"></script>
<img src="/filler/sample.jpg?8">
<iframe src="/filler/sample2.jpg?8"></iframe>
</body>
</head>
17 changes: 16 additions & 1 deletion test/fixtures-integration-tag/__setProps.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
<script>
var params = JSON.parse(decodeURIComponent(window.location.search.substring(1)));
// This is an intermediate page that sets up state (window.name, cookies)
// for a page that is about to be tested.

var payload = decodeURIComponent(window.location.search.substring(1));

// Allow #{...} templating on initialization parameters
var values = {
host: location.hostname
}

payload = payload.replace(/#\{([^\}]+)\}/, function(all, key) {
if (key in values) return values[key];
return all;
});

var params = JSON.parse(payload);

if (params.name) window.name = params.name;

Expand Down
Empty file.
Binary file not shown.
Empty file.
Binary file not shown.
Empty file.
Binary file not shown.
Empty file.
Binary file not shown.
Empty file.
Binary file not shown.
Empty file.
Binary file not shown.
Empty file.
Binary file not shown.
Empty file.
Binary file not shown.
Empty file.
Binary file not shown.
Empty file.
Binary file not shown.
Empty file.
Binary file not shown.
Empty file.
Binary file not shown.
Empty file.
Binary file not shown.
Empty file.
Binary file not shown.
Empty file.
Binary file not shown.
Empty file.
Binary file not shown.
Empty file.
Binary file not shown.
Empty file.
Binary file not shown.
Empty file.
Binary file not shown.
Empty file.
Binary file not shown.
Empty file.
Binary file not shown.
Empty file.
Binary file not shown.
Empty file.
Binary file not shown.
Empty file.
Binary file not shown.
Empty file.
Binary file not shown.
Empty file.
Diff not rendered.
Empty file.
Diff not rendered.
Empty file.
Diff not rendered.
Empty file.
Binary file removed test/fixtures-integration-tag/filler/example.jpg
Diff not rendered.
10 changes: 5 additions & 5 deletions test/fixtures-integration-tag/manifest.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"tests": [{
"path": "removeResources",
"project": "removeResources",
"tagVersion" : "../../test/fixtures-integration-tag/7-pure",
"start": {
"init": {
"href": "__injectTag/7firstload.html",
"cookie": ["mobify-capture=; domain=.127.0.0.1; path=/; expires=Thu, 01 Jan 1970 00:00:01 GMT;"]
"cookie": ["mobify-capture=; domain=.#{host}; path=/; expires=Thu, 01 Jan 1970 00:00:01 GMT;"]
}
},
{
"path": "removeResources",
"project": "removeResources",
"tagVersion" : "../../test/fixtures-integration-tag/7-pure",
"start": { "href": "__injectTag/7secondload.html" }
"init": { "href": "__injectTag/7secondload.html" }
}]
}
69 changes: 56 additions & 13 deletions test/fixtures-integration-tag/verify.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,49 @@
(function() {
// This file will validate state of page after tag/detector/konf have their
// way with it. To validate the state, it needs to figure out what page it is,
// and what is expected to happen on that page for the current device.

// For example, a mobile device would be expected to capture content and
// strictly limit number of requests it loads.
// Meanwhile, desktop browsers are expected to not capture content,
// load detector script and retain all existing page content.

Mobify.api = 1; // Let tag know that unmobify is not needed

// Since actual state tracking happens on server, errors have to be reported
// via an HTTP request.
var report = function(msg) {
var url = 'http://' + location.hostname + ':1343/endTest';
if (msg) url = url + '?msg=' + encodeURIComponent(msg);
location.href = url;
report = function(){};
}

// Once we successfully figure out what expectations the current page
// should conform to, we want to terminate all processing and exit all loops
// The simplest way to accomplish that is to throw a not-really-exception
// object. Yes, it is the new goto.
var success = {};


// Recursive expectation validator, essentially a multilevel konf choose()
// At every level, it chooses a branch to go into.
// If branch contains subbranches, one will be chosen once again.
// If branch contains only a function body, that function will be run,
// and the search is ended.
// If no branch can be chosen, checkBranch fails. In practice, this would
// happen if it is invoked on unknown page, by unknown device, or in a
// similar 'everything is wrong' scenario.

// Branches are chosen based on property matching a regular expression
// or a test function. First parameter of a branch is the variable to be
// tested, and second is a function or regexp that accepts or rejects the
// value of property. checkBranch will walk into accepted branch, and will
// skip rejected ones until it runs out of branches at current level.

// checkBranch will not back out of a previously chosen branch if
// all its subbranches fail.

var checkBranch = function(props, validators) {
validators.forEach(function(validator) {
if (validator instanceof Function) {
Expand All @@ -29,52 +63,61 @@
}
}
});
debugger;
throw new Error('Unknown testcase');
}

var verify = function() {
try {
var request = new XMLHttpRequest();
request.open('GET', '/__listRequests', false);
request.send();

var requestList = request.responseText.split('\n');

// Property values that will be used by checkBranch
var props = {
'ua' : navigator.userAgent
, 'path': location.pathname
, 'capture' : '' + !!(Mobify.transform || document.querySelectorAll('plaintext').length)
, 'reqs' : (function() {
var request = new XMLHttpRequest();
request.open('GET', '/__listRequests', false);
request.send();

return request.responseText.split('\n').length;
})()
, 'reqs' : requestList.length // Number of HTTP requests
};

// This simple test suite we will handle only iPhone and desktop
// browsers. We should add support for Androids, and differentiate
// between old/new ones (determines if window.stop() trick works)
// and between handsets and tablets.
checkBranch(props, [
['path', /\/7firstload\.html$/
, ['ua', /iphone/i, function() {
['capture', 'true', function() {
// window.stop() trick should limit, but can't prevent leakage
if (props.reqs >= 12) throw 'Leaked too much ' + props.reqs;
}]
}]
, ['capture', 'false', function() {
// 27 requests + 1 file + 1 detector.js
// All content should properly load
// 27 content requests + 1 file + 1 detector.js
if (props.reqs !== 29) throw 'Failed to load normal desktop resources' + props.reqs;
}]
]
, ['path', /\/7secondload\.html$/
, ['ua', /iphone/i,
// After first page setting cookie through detector,
// subsequent visits should leak nothing at all
['capture', 'true', function() {
if (props.reqs !== 2) throw 'Leaked at all' + props.reqs;
}]
]
, ['capture', 'false', function() {
// 27 requests + 1 file + 1 detector.js
// 27 content requests + 1 file + 1 detector.js
if (props.reqs !== 29) throw 'Failed to load normal desktop resources' + props.reqs;
}]
]
]);
} catch (ex) {
console.log(ex);
// Found and verified a single testing branch
if (ex !== success) {
alert(ex.toString());
window.console && console.error(ex);
}
}
};
if (document.readyState !== "loading") {
Expand Down
Loading

0 comments on commit 9c6eb30

Please sign in to comment.