Skip to content

Commit

Permalink
Improve WebPage CJK support tests.
Browse files Browse the repository at this point in the history
This is for issue ariya#10249: ariya#10249.
  • Loading branch information
execjosh authored and ariya committed Apr 23, 2013
1 parent 3edcabe commit d925a51
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 25 deletions.
48 changes: 48 additions & 0 deletions test/cjk-text-codecs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
describe("WebPage CJK support", function () {
var texts = [
new Text("Shift_JIS", "g3SDQIOTg2eDgA==", "ファントム")
, new Text("EUC-JP", "pdWloaXzpcil4A0K", "ファントム")
, new Text("ISO-2022-JP", "GyRCJVUlISVzJUglYBsoQg0K", "ファントム")
, new Text("Big5", "pNu2SA0K", "幻象")
, new Text("GBK", "u8PP8w0K", "幻象")
, new Text("EUC-KR", "yK+/tQ==", "환영")
];

texts.forEach(function (t) {
it(t.codec, function() {
var decodedText = -1;
var page = new WebPage();

page.open(t.dataUrl(), function(status) {
decodedText = page.evaluate(function() {
return document.getElementsByTagName("pre")[0].innerText;
});
page.close();
});

waitsFor(function () {
return -1 !== decodedText;
}, "Text not decoded within three seconds", 3000);

runs(function () {
expect(t.check(decodedText)).toBeTruthy();
});
});
});

function Text(codec, base64, reference) {
this.codec = codec;
this.base64 = base64;
this.reference = reference;
}

Text.prototype.dataUrl = function () {
return "data:text/plain;charset=" + this.codec + ";base64," + this.base64;
};

Text.prototype.check = function (decodedText) {
return decodedText.match("^" + this.reference) == this.reference;
};
});

// vim:ts=4:sw=4:sts=4:et:
1 change: 1 addition & 0 deletions test/run-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ phantom.injectJs("./system-spec.js");
phantom.injectJs("./webkit-spec.js");
require("./module_spec.js");
require("./require/require_spec.js");
require("./cjk-text-codecs.js");

// Launch tests
var jasmineEnv = jasmine.getEnv();
Expand Down
25 changes: 0 additions & 25 deletions test/webpage-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1390,31 +1390,6 @@ describe("WebPage construction with options", function () {
};
checkViewportSize(new WebPage(opts), opts.viewportSize);
});

var texts = [
{ codec: 'Shift_JIS', base64: 'g3SDQIOTg2eDgA==', reference: 'ファントム'},
{ codec: 'EUC-JP', base64: 'pdWloaXzpcil4A0K', reference: 'ファントム'},
{ codec: 'ISO-2022-JP', base64: 'GyRCJVUlISVzJUglYBsoQg0K', reference: 'ファントム'},
{ codec: 'Big5', base64: 'pNu2SA0K', reference: '幻象'},
{ codec: 'GBK', base64: 'u8PP8w0K', reference: '幻象'}
];
for (var i = 0; i < texts.length; ++i) {
describe("Text codec support", function() {
var text = texts[i];
var dataUrl = 'data:text/plain;charset=' + text.codec + ';base64,' + text.base64;
var page = new WebPage();
var decodedText;
page.open(dataUrl, function(status) {
decodedText = page.evaluate(function() {
return document.getElementsByTagName('pre')[0].innerText;
});
page.close();
});
it("Should support text codec " + text.codec, function() {
expect(decodedText.match("^" + text.reference) == text.reference).toEqual(true);
});
});
}
});

describe("WebPage switch frame of execution (deprecated API)", function(){
Expand Down

0 comments on commit d925a51

Please sign in to comment.