Import code from internal repository to git

This commit is contained in:
Justine Tunney 2016-03-01 17:18:14 -05:00
commit 0ef0c933d2
2490 changed files with 281594 additions and 0 deletions

View file

@ -0,0 +1,23 @@
package(default_visibility = ["//java/com/google/domain/registry:registry_project"])
load("//third_party/closure/compiler:closure_js_library.bzl", "closure_js_library")
load("//third_party/closure/testing:closure_js_test.bzl", "closure_js_test")
closure_js_library(
name = "testing",
srcs = ["testing.js"],
deps = ["//javascript/closure"],
)
closure_js_test(
name = "test",
size = "medium",
timeout = "short",
srcs = glob(["*_test.js"]),
deps = [
":testing",
"//java/com/google/domain/registry/ui/js",
"//javascript/closure",
],
)

View file

@ -0,0 +1,17 @@
package(default_visibility = ["//java/com/google/domain/registry:registry_project"])
load("//third_party/closure/testing:closure_js_test.bzl", "closure_js_test")
closure_js_test(
name = "test",
size = "medium",
timeout = "short",
srcs = glob(["*_test.js"]),
deps = [
"//java/com/google/domain/registry/ui/js/admin",
"//java/com/google/domain/registry/ui/soy/admin:Console",
"//javascript/closure",
"//javatests/com/google/domain/registry/ui/js:testing",
],
)

View file

@ -0,0 +1,306 @@
// Copyright 2016 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
goog.setTestOnly();
goog.require('goog.History');
goog.require('goog.dispose');
goog.require('goog.dom');
goog.require('goog.soy');
goog.require('goog.string');
goog.require('goog.testing.MockControl');
goog.require('goog.testing.PropertyReplacer');
goog.require('goog.testing.asserts');
goog.require('goog.testing.jsunit');
goog.require('goog.testing.mockmatchers');
goog.require('goog.testing.net.XhrIo');
goog.require('registry.admin.Console');
goog.require('registry.soy.admin.console');
goog.require('registry.testing');
var $ = goog.dom.getRequiredElement;
var _ = goog.testing.mockmatchers.ignoreArgument;
var stubs = new goog.testing.PropertyReplacer();
var mocks = new goog.testing.MockControl();
var historyMock;
var adminConsole;
function setUp() {
registry.testing.addToDocument('<div id="test"/>');
goog.soy.renderElement($('test'), registry.soy.admin.console.main, {
xsrfToken: 'ignore',
clientIdentifier: 'ignore',
user: {
'id': 'go@daddy.tld',
'actionHref': 'http://godaddy.com',
'actionName': 'ignore'
}
});
stubs.setPath('goog.net.XhrIo', goog.testing.net.XhrIo);
historyMock = mocks.createStrictMock(goog.History);
mocks.createConstructorMock(goog, 'History')().$returns(historyMock);
historyMock.addEventListener(_, _, _);
historyMock.setEnabled(true);
mocks.$replayAll();
adminConsole = new registry.admin.Console('༼༎෴ ༎༽');
mocks.$verifyAll();
}
function tearDown() {
goog.dispose(adminConsole);
stubs.reset();
mocks.$tearDown();
goog.testing.net.XhrIo.cleanup();
}
function testCollectionView() {
historyMock.$reset();
historyMock.getToken().$returns('registrar');
mocks.$replayAll();
adminConsole.handleHashChange();
registry.testing.assertReqMockRsp(
'༼༎෴ ༎༽',
'/_dr/admin/registrar',
{op: 'read', args: {}},
{set: []});
assertEquals('We require more vespene gas.',
0, goog.testing.net.XhrIo.getSendInstances().length);
mocks.$verifyAll();
assertNotNull($('clientIdentifier'));
}
function testCreate() {
testCollectionView();
var testRegistrar = createTestRegistrar();
$('clientIdentifier').value = testRegistrar.clientIdentifier;
$('registrarName').value = testRegistrar.registrarName;
$('icannReferralEmail').value = testRegistrar.icannReferralEmail;
$('emailAddress').value = testRegistrar.emailAddress;
$('localizedAddress.street[0]').value =
testRegistrar.localizedAddress.street[0];
$('localizedAddress.city').value = testRegistrar.localizedAddress.city;
$('localizedAddress.countryCode').value =
testRegistrar.localizedAddress.countryCode;
registry.testing.click($('create-button'));
registry.testing.assertReqMockRsp(
'༼༎෴ ༎༽',
'/_dr/admin/registrar/daddy', {
op: 'create',
args: testRegistrar
},
{results: ['daddy: ok']});
testRegistrar.state = 'PENDING';
testRegistrar.lastUpdateTime = '2014-08-11T21:57:58.801Z';
testRegistrar.creationTime = '2014-08-11T21:57:58.801Z';
registry.testing.assertReqMockRsp(
'༼༎෴ ༎༽',
'/_dr/admin/registrar/daddy',
{op: 'read', args: {}},
{item: testRegistrar });
mocks.$verifyAll();
assertEquals('We require more vespene gas.',
0, goog.testing.net.XhrIo.getSendInstances().length);
assertEquals('daddy',
goog.dom.getElementsByTagNameAndClass('h1')[0].innerHTML);
assertEquals('PENDING', $('state').value);
historyMock.$reset();
historyMock.getToken().$returns('registrar');
mocks.$replayAll();
adminConsole.handleHashChange();
registry.testing.assertReqMockRsp(
'༼༎෴ ༎༽',
'/_dr/admin/registrar',
{op: 'read', args: {}},
{set: [testRegistrar]});
assertEquals('We require more vespene gas.',
0, goog.testing.net.XhrIo.getSendInstances().length);
mocks.$verifyAll();
}
function testItemViewEditSave() {
testCreate();
historyMock.$reset();
historyMock.getToken().$returns('registrar/daddy');
mocks.$replayAll();
adminConsole.handleHashChange();
var testRegistrar = createTestRegistrar();
registry.testing.assertReqMockRsp(
'༼༎෴ ༎༽',
'/_dr/admin/registrar/daddy',
{op: 'read', args: {}},
{item: testRegistrar });
assertEquals('We require more vespene gas.',
0, goog.testing.net.XhrIo.getSendInstances().length);
mocks.$verifyAll();
assertTrue('Form should be read-only.', $('registrarName').readOnly);
registry.testing.click($('reg-app-btn-edit'));
assertFalse('Form should be edible.', $('registrarName').readOnly);
testRegistrar.registrarName = 'GoDaddy';
testRegistrar.emailAddress = 'new@email.com';
testRegistrar.icannReferralEmail = 'new@referral.com';
testRegistrar.state = 'ACTIVE';
testRegistrar.allowedTlds = 'foo,bar,baz';
testRegistrar.driveFolderId = 'driveFolderId';
testRegistrar.phoneNumber = '+1.2345678900';
testRegistrar.faxNumber = '+1.2345678900';
testRegistrar.whoisServer = 'blah.blee.foo';
testRegistrar.blockPremiumNames = true;
testRegistrar.localizedAddress = {
street: ['mean', '', ''],
city: 'NYC',
state: 'AZ',
zip: '5555',
countryCode: 'NZ'
};
testRegistrar.clientCertificate = '-----BEGIN CERTIFICATE-----' +
'MIIDvTCCAqWgAwIBAgIJAK/PgPT0jTwRMA0GCSqGSIb3DQEBCwUAMHUxCzAJBgNV' +
'BAYTAlVTMREwDwYDVQQIDAhOZXcgWW9yazERMA8GA1UEBwwITmV3IFlvcmsxDzAN' +
'BgNVBAoMBkdvb2dsZTEdMBsGA1UECwwUZG9tYWluLXJlZ2lzdHJ5LXRlc3QxEDAO' +
'BgNVBAMMB2NsaWVudDEwHhcNMTUwODI2MTkxODA4WhcNNDMwMTExMTkxODA4WjB1' +
'MQswCQYDVQQGEwJVUzERMA8GA1UECAwITmV3IFlvcmsxETAPBgNVBAcMCE5ldyBZ' +
'b3JrMQ8wDQYDVQQKDAZHb29nbGUxHTAbBgNVBAsMFGRvbWFpbi1yZWdpc3RyeS10' +
'ZXN0MRAwDgYDVQQDDAdjbGllbnQxMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB' +
'CgKCAQEAvoE/IoFJyzb0dU4NFhL8FYgy+B/GnUd5aA66CMx5xKRMbEAtIgxU8TTO' +
'W+9jdTsE00Grk3Ct4KdY73CYW+6IFXL4O0K/m5S+uajh+I2UMVZJV38RAIqNxue0' +
'Egv9M4haSsCVIPcX9b+6McywfYSF1bzPb2Gb2FAQO7Jb0BjlPhPMIROCrbG40qPg' +
'LWrl33dz+O52kO+DyZEzHqI55xH6au77sMITsJe+X23lzQcMFUUm8moiOw0EKrj/' +
'GaMTZLHP46BCRoJDAPTNx55seIwgAHbKA2VVtqrvmA2XYJQA6ipdhfKRoJFy8Z8H' +
'DYsorGtazQL2HhF/5uJD25z1m5eQHQIDAQABo1AwTjAdBgNVHQ4EFgQUParEmiSR' +
'U/Oqy8hr7k+MBKhZwVkwHwYDVR0jBBgwFoAUParEmiSRU/Oqy8hr7k+MBKhZwVkw' +
'DAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEAojsUhF6PtZrStnHBFWNR' +
'ryzvANB8krZlYeX9Hkqn8zIVfAkpbVmL8aZQ7yj17jSpw47PQh3x5gwA9yc/SS0G' +
'E1rGuxYH02UGbua8G0+vviSQfLtskPQzK7EIR63WNhHEo/Q9umLJkZ0LguWEBf3L' +
'q8CoXv2i/RNvqVPcTNp/zCKXJZAa8wAjNRJs834AZj4k5xwyYZ3F8D5PGz+YMOmV' +
'M9Qd+NdXSC/Qn7HQzFhE8p5elBV35P8oX5dXEfn0S7zOXDenp5JvvLoggOWOcKsq' +
'KiWDQrsT+TMKmHL94/h4t7FghtQLMzY5SGYJsYTv/LG8tewrz6KRb/Wj3JNojyEw' +
'Ug==' +
'-----END CERTIFICATE-----';
testRegistrar.phonePasscode = '01234';
testRegistrar.ipAddressWhitelist = '1.1.1.1,2.2.2.2';
testRegistrar.password = 'yoyoSheep';
testRegistrar.billingIdentifier = '12345';
testRegistrar.ianaIdentifier = '11111';
testRegistrar.url = 'http://yoyo.com';
testRegistrar.referralUrl = 'http://other.com';
testRegistrar.contacts = [{
name: 'Joe',
emailAddress: 'joe@go.com',
phoneNumber: '',
faxNumber: '',
types: 'ADMIN,TECH',
gaeUserId: '1234'
}, {
name: 'Jane',
emailAddress: 'joe@go.com',
phoneNumber: '',
faxNumber: '',
types: '',
gaeUserId: '5432'
}];
for (var i in testRegistrar) {
// Not all keys are present as inputs with id,
// e.g. clientIdentifier.
var inputElt = goog.dom.getElement(i);
if (inputElt) {
inputElt.value = testRegistrar[i];
}
if (i == 'contacts' ||
i == 'localizedAddress' ||
i == 'blockPremiumNames') {
continue;
}
}
if (testRegistrar.blockPremiumNames) {
$('blockPremiumNames').setAttribute('checked', true);
}
var addr = testRegistrar['localizedAddress'];
$('localizedAddress.street[0]').value = addr.street[0];
$('localizedAddress.street[1]').value = addr.street[1];
$('localizedAddress.street[2]').value = addr.street[2];
$('localizedAddress.city').value = addr.city;
$('localizedAddress.state').value = addr.state;
$('localizedAddress.zip').value = addr.zip;
$('localizedAddress.countryCode').value = addr.countryCode;
var contacts = testRegistrar['contacts'];
for (var c = 0; c < contacts.length; c++) {
registry.testing.click($('add-contact-button'));
var contact = contacts[c];
for (var ci in contact) {
// Form IDs are the full path ref.
$('contacts[' + c + '].' + ci).value = contact[ci];
}
}
registry.testing.click($('reg-app-btn-save'));
// Convert string to wire vals for assert comparison.
testRegistrar.billingIdentifier =
goog.string.parseInt(testRegistrar.billingIdentifier);
testRegistrar.ianaIdentifier =
goog.string.parseInt(testRegistrar.ianaIdentifier);
testRegistrar.allowedTlds = testRegistrar.allowedTlds.split(',');
testRegistrar.ipAddressWhitelist =
testRegistrar.ipAddressWhitelist.split(',');
// And the readonly field the client adds.
testRegistrar.readonly = false;
registry.testing.assertReqMockRsp(
'༼༎෴ ༎༽',
'/_dr/admin/registrar/daddy',
{op: 'update', args: testRegistrar},
{results: ['daddy: ok']});
registry.testing.assertReqMockRsp(
'༼༎෴ ༎༽',
'/_dr/admin/registrar/daddy',
{op: 'read', args: {}},
{item: testRegistrar});
assertEquals('We require more vespene gas.',
0, goog.testing.net.XhrIo.getSendInstances().length);
mocks.$verifyAll();
}
/** @return {!Object.<string, ?>} */
function createTestRegistrar() {
return {
clientIdentifier: 'daddy',
registrarName: 'The Daddy',
icannReferralEmail: 'lol@sloth.test',
emailAddress: 'foo@bar.com',
localizedAddress: {
street: ['111 8th Ave.'],
city: 'NYC',
countryCode: 'NZ'
}
};
}

View file

@ -0,0 +1,207 @@
// Copyright 2016 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
goog.setTestOnly();
goog.require('goog.History');
goog.require('goog.dispose');
goog.require('goog.dom');
goog.require('goog.soy');
goog.require('goog.testing.MockControl');
goog.require('goog.testing.PropertyReplacer');
goog.require('goog.testing.asserts');
goog.require('goog.testing.jsunit');
goog.require('goog.testing.mockmatchers');
goog.require('goog.testing.net.XhrIo');
goog.require('registry.admin.Console');
goog.require('registry.soy.admin.console');
goog.require('registry.testing');
var $ = goog.dom.getRequiredElement;
var _ = goog.testing.mockmatchers.ignoreArgument;
var stubs = new goog.testing.PropertyReplacer();
var mocks = new goog.testing.MockControl();
var historyMock;
var adminConsole;
function setUp() {
registry.testing.addToDocument('<div id="test"/>');
goog.soy.renderElement($('test'), registry.soy.admin.console.main, {
xsrfToken: 'ignore',
clientId: 'ignore',
user: {
'id': 'go@daddy.tld',
'actionHref': 'http://godaddy.com',
'actionName': 'ignore'
}
});
stubs.setPath('goog.net.XhrIo', goog.testing.net.XhrIo);
historyMock = mocks.createStrictMock(goog.History);
mocks.createConstructorMock(goog, 'History')().$returns(historyMock);
historyMock.addEventListener(_, _, _);
historyMock.setEnabled(true);
mocks.$replayAll();
adminConsole = new registry.admin.Console('༼༎෴ ༎༽');
mocks.$verifyAll();
}
function tearDown() {
goog.dispose(adminConsole);
stubs.reset();
mocks.$tearDown();
goog.testing.net.XhrIo.cleanup();
}
function testCollectionView() {
historyMock.$reset();
historyMock.getToken().$returns('registry');
mocks.$replayAll();
adminConsole.handleHashChange();
registry.testing.assertReqMockRsp(
'༼༎෴ ༎༽',
'/_dr/admin/registry',
{op: 'read', args: {}},
{set: []});
assertEquals('We require more vespene gas.',
0, goog.testing.net.XhrIo.getSendInstances().length);
mocks.$verifyAll();
assertNotNull($('newTldName'));
}
/** Creates test registry. */
function createTestRegistry() {
return {
addGracePeriod: 'PT432000S',
autoRenewGracePeriod: 'PT3888000S',
automaticTransferLength: 'PT432000S',
name: 'foo',
pendingDeleteLength: 'PT432000S',
redemptionGracePeriod: 'PT2592000S',
renewGracePeriod: 'PT432000S',
state: 'PREDELEGATION',
tldStateTransitions: '{1970-01-01T00:00:00.000Z=PREDELEGATION}',
transferGracePeriod: 'PT432000S'
};
}
function testCreate() {
testCollectionView();
$('newTldName').value = 'foo';
registry.testing.click($('create-button'));
registry.testing.assertReqMockRsp(
'༼༎෴ ༎༽',
'/_dr/admin/registry/foo', {
op: 'create',
args: {
newTldName: 'foo'
}
},
{results: ['foo: ok']});
var testReg = createTestRegistry();
testReg.creationTime = '2014-08-07T20:35:39.142Z';
testReg.lastUpdateTime = '2014-08-07T20:35:39.142Z';
registry.testing.assertReqMockRsp(
'༼༎෴ ༎༽',
'/_dr/admin/registry/foo',
{op: 'read', args: {}},
{item: testReg });
mocks.$verifyAll();
assertEquals('We require more vespene gas.',
0, goog.testing.net.XhrIo.getSendInstances().length);
assertEquals('foo', goog.dom.getElementsByTagNameAndClass('h1')[0].innerHTML);
historyMock.$reset();
historyMock.getToken().$returns('registry');
mocks.$replayAll();
adminConsole.handleHashChange();
registry.testing.assertReqMockRsp(
'༼༎෴ ༎༽',
'/_dr/admin/registry',
{op: 'read', args: {}},
{set: [testReg]});
assertEquals('We require more vespene gas.',
0, goog.testing.net.XhrIo.getSendInstances().length);
mocks.$verifyAll();
}
function testItemViewEditSave() {
testCreate();
historyMock.$reset();
historyMock.getToken().$returns('registry/foo');
mocks.$replayAll();
adminConsole.handleHashChange();
var testReg = createTestRegistry();
registry.testing.assertReqMockRsp(
'༼༎෴ ༎༽',
'/_dr/admin/registry/foo',
{op: 'read', args: {}},
{item: testReg });
assertEquals('We require more vespene gas.',
0, goog.testing.net.XhrIo.getSendInstances().length);
mocks.$verifyAll();
assertTrue('Form should be read-only.', $('addGracePeriod').readOnly);
registry.testing.click($('reg-app-btn-edit'));
assertFalse('Form should be editable.', $('addGracePeriod').readOnly);
// Edit state
testReg.tldStateTransitions = 'GENERAL_AVAILABILITY,1970-01-01T00:00:00.000Z';
for (var i in testReg) {
// Not all keys are present as inputs with id,
// e.g. name.
var inputElt = goog.dom.getElement(i);
if (inputElt) {
inputElt.value = testReg[i];
}
}
registry.testing.click($('reg-app-btn-save'));
// Convert string to wire vals.
var tldStateTransitionStr = testReg.tldStateTransitions;
testReg.tldStateTransitions = [{
tldState: 'GENERAL_AVAILABILITY',
transitionTime: '1970-01-01T00:00:00.000Z'
}];
// And the readonly field the client adds.
testReg.readonly = false;
registry.testing.assertReqMockRsp(
'༼༎෴ ༎༽',
'/_dr/admin/registry/foo',
{op: 'update', args: testReg},
{results: ['foo: ok']});
// Restore the stringified version.
testReg.tldStateTransitions = tldStateTransitionStr;
registry.testing.assertReqMockRsp(
'༼༎෴ ༎༽',
'/_dr/admin/registry/foo',
{op: 'read', args: {}},
{item: testReg});
assertEquals('We require more vespene gas.',
0, goog.testing.net.XhrIo.getSendInstances().length);
mocks.$verifyAll();
}

View file

@ -0,0 +1,43 @@
// Copyright 2016 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
goog.setTestOnly();
goog.require('goog.dispose');
goog.require('goog.testing.MockControl');
goog.require('goog.testing.jsunit');
goog.require('registry.Component');
goog.require('registry.Console');
var mocks = new goog.testing.MockControl();
function setUp() {
mocks = new goog.testing.MockControl();
}
function tearDown() {
mocks.$tearDown();
}
function testCreationAndDisposal_dontTouchConsoleObject() {
var console = mocks.createStrictMock(registry.Console);
mocks.$replayAll();
var component = new registry.Component(console);
goog.dispose(component);
mocks.$verifyAll();
}

View file

@ -0,0 +1,30 @@
package(default_visibility = ["//java/com/google/domain/registry:registry_project"])
load("//third_party/closure/compiler:closure_js_library.bzl", "closure_js_library")
load("//third_party/closure/testing:closure_js_test.bzl", "closure_js_test")
closure_js_library(
name = "console_test_util",
srcs = ["console_test_util.js"],
deps = [
"//java/com/google/domain/registry/ui/js",
"//java/com/google/domain/registry/ui/js/registrar",
"//javascript/closure",
],
)
closure_js_test(
name = "test",
size = "medium",
timeout = "short",
srcs = glob(["*_test.js"]),
deps = [
":console_test_util",
"//java/com/google/domain/registry/ui/js",
"//java/com/google/domain/registry/ui/js/registrar",
"//java/com/google/domain/registry/ui/soy/registrar:Console",
"//javascript/closure",
"//javatests/com/google/domain/registry/ui/js:testing",
],
)

View file

@ -0,0 +1,97 @@
// Copyright 2016 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
goog.setTestOnly();
goog.require('goog.dispose');
goog.require('goog.dom');
goog.require('goog.style');
goog.require('goog.testing.MockControl');
goog.require('goog.testing.asserts');
goog.require('goog.testing.jsunit');
goog.require('registry.registrar.BrainFrame');
goog.require('registry.testing');
var mocks = new goog.testing.MockControl();
var brainframe;
var mockPostMessage;
function setUp() {
registry.testing.addToDocument('<form><div id="bf"></div></form>');
brainframe = new registry.registrar.BrainFrame('omg', 'bf');
mockPostMessage =
mocks.createMethodMock(registry.registrar.BrainFrame, 'postMessage_');
}
function tearDown() {
goog.dispose(brainframe);
mocks.$tearDown();
}
function testRun_sendsTokenRequestToParent() {
mockPostMessage('{"type":"token_request"}', 'omg');
mocks.$replayAll();
brainframe.run();
mocks.$verifyAll();
}
function testTokenResponseMessage_callsSetup() {
var called = false;
goog.global.braintree = {};
goog.global.braintree.setup = function(token, mode, args) {
called = true;
assertEquals('imatoken', token);
assertEquals('dropin', mode);
assertEquals('bf', args.container.id);
};
brainframe.onMessage_({
getBrowserEvent: function() {
return {
source: window.parent,
origin: 'omg',
data: '{"type": "token_response", "token": "imatoken"}'
};
}
});
assertTrue(called);
}
function testPaymentMethodMessage_sendsInfo() {
mockPostMessage('{"type":"payment_method","submit":false,"method":"hi"}',
'omg');
mocks.$replayAll();
brainframe.onPaymentMethod_('hi');
mocks.$verifyAll();
}
function testOnResizeTimer_sendsHeight() {
mockPostMessage('{"type":"resize_request","height":123}', 'omg');
mocks.$replayAll();
goog.style.setHeight(goog.dom.getElement('bf'), 123);
brainframe.onResizeTimer_();
mocks.$verifyAll();
// But does not send height if size hasn't changed.
mocks.$replayAll();
brainframe.onResizeTimer_();
mocks.$verifyAll();
}

View file

@ -0,0 +1,156 @@
// Copyright 2016 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
goog.setTestOnly();
goog.require('goog.dom');
goog.require('goog.dom.classlist');
goog.require('goog.json');
goog.require('goog.soy');
goog.require('goog.testing.MockControl');
goog.require('goog.testing.PropertyReplacer');
goog.require('goog.testing.asserts');
goog.require('goog.testing.jsunit');
goog.require('goog.testing.mockmatchers');
goog.require('goog.testing.net.XhrIo');
goog.require('registry.registrar.ConsoleTestUtil');
goog.require('registry.soy.registrar.console');
goog.require('registry.testing');
goog.require('registry.util');
var $ = goog.dom.getRequiredElement;
var stubs = new goog.testing.PropertyReplacer();
var test = {
testXsrfToken: 'testToken',
testClientId: 'daddy',
mockControl: new goog.testing.MockControl()
};
function setUp() {
registry.testing.addToDocument('<div id="test"/>');
registry.testing.addToDocument('<div class="kd-butterbar"/>');
stubs.setPath('goog.net.XhrIo', goog.testing.net.XhrIo);
var testElt = goog.dom.getElement('test');
goog.soy.renderElement(testElt, registry.soy.registrar.console.main, {
user: {
id: 'pmy@google.com',
actionHref: 'blah'
},
xsrfToken: test.testXsrfToken,
clientId: test.testClientId
});
registry.registrar.ConsoleTestUtil.setup(test);
var regNavlist = $('reg-navlist');
var active = regNavlist.querySelector('a[href="/registrar#contact-us"]');
assertTrue(active != null);
}
function tearDown() {
goog.testing.net.XhrIo.cleanup();
stubs.reset();
test.mockControl.$tearDown();
}
function testButter() {
registry.registrar.ConsoleTestUtil.visit(test);
registry.util.butter('butter msg');
var butter = goog.dom.getElementByClass(goog.getCssName('kd-butterbar'));
assertNotNull(butter.innerHTML.match(/.*butter msg.*/));
assertTrue(goog.dom.classlist.contains(butter, goog.getCssName('shown')));
}
/**
* The EPP login should be triggered if the user {@code isGaeLoggedIn}
* but not yet {@code isEppLoggedIn}.
*/
function testEppLogin() {
// This is a little complex, as handleHashChange triggers an async
// event to do the EPP login with a callback to come back to
// handleHashChange after completion.
registry.registrar.ConsoleTestUtil.visit(
test, {
isEppLoggedIn: true,
testClientId: test.testClientId,
testXsrfToken: test.testXsrfToken
}, function() {
test.sessionMock.login(
goog.testing.mockmatchers.isFunction).$does(function() {
test.sessionMock.$reset();
test.sessionMock.isEppLoggedIn().$returns(true).$anyTimes();
test.sessionMock.getClientId().$returns(
test.testClientId).$anyTimes();
test.sessionMock.$replay();
test.console.handleHashChange(test.testClientId);
}).$anyTimes();
});
assertTrue(test.console.session.isEppLoggedIn());
assertNotNull(goog.dom.getElement('domain-registrar-dashboard'));
}
/** Authed user with no path op specified should nav to welcome page. */
function testShowLoginOrDash() {
registry.registrar.ConsoleTestUtil.visit(test);
assertNotNull(goog.dom.getElement('domain-registrar-dashboard'));
}
function testNavToResources() {
registry.registrar.ConsoleTestUtil.visit(test, {
path: 'resources',
testXsrfToken: test.testXsrfToken
});
var xhr = goog.testing.net.XhrIo.getSendInstances().pop();
assertTrue(xhr.isActive());
assertEquals('/registrar-settings', xhr.getLastUri());
assertEquals(test.testXsrfToken,
xhr.getLastRequestHeaders().get('X-CSRF-Token'));
xhr.simulateResponse(200, goog.json.serialize({
status: 'SUCCESS',
message: 'OK',
results: [{
driveFolderId: 'blahblah'
}]
}));
assertContains('blahblah', $('reg-resources-driveLink').getAttribute('href'));
}
function testNavToContactUs() {
registry.registrar.ConsoleTestUtil.visit(test, {
path: 'contact-us',
testXsrfToken: test.testXsrfToken
});
var xhr = goog.testing.net.XhrIo.getSendInstances().pop();
assertTrue(xhr.isActive());
assertEquals('/registrar-settings', xhr.getLastUri());
assertEquals(test.testXsrfToken,
xhr.getLastRequestHeaders().get('X-CSRF-Token'));
var passcode = '5-5-5-5-5';
xhr.simulateResponse(200, goog.json.serialize({
status: 'SUCCESS',
message: 'OK',
results: [{
phonePasscode: passcode
}]
}));
assertEquals(passcode,
goog.dom.getTextContent($('domain-registrar-phone-passcode')));
}

View file

@ -0,0 +1,95 @@
// Copyright 2016 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
goog.provide('registry.registrar.ConsoleTestUtil');
goog.setTestOnly('registry.registrar.ConsoleTestUtil');
goog.require('goog.History');
goog.require('goog.asserts');
goog.require('goog.dom.xml');
goog.require('goog.testing.mockmatchers');
goog.require('registry.registrar.Console');
goog.require('registry.registrar.EppSession');
goog.require('registry.xml');
/**
* Utility method that attaches mocks to a {@code TestCase}. This was
* originally in the ctor for ConsoleTest and should simply be
* inherited but jstd_test breaks inheritance in test cases.
* @param {Object} test the test case to configure.
*/
registry.registrar.ConsoleTestUtil.setup = function(test) {
test.historyMock = test.mockControl.createLooseMock(goog.History, true);
test.sessionMock = test.mockControl.createLooseMock(
registry.registrar.EppSession, true);
/** @suppress {missingRequire} */
test.mockControl.createConstructorMock(goog, 'History')()
.$returns(test.historyMock);
/** @suppress {missingRequire} */
test.mockControl
.createConstructorMock(registry.registrar, 'EppSession')(
goog.testing.mockmatchers.isObject,
goog.testing.mockmatchers.isString,
goog.testing.mockmatchers.isString)
.$returns(test.sessionMock);
};
/**
* Simulates visiting a page on the console. Sets path, then mocks
* session and calls {@code handleHashChange_}.
* @param {Object} test the test case to configure.
* @param {Object=} opt_args may include path, isEppLoggedIn.
* @param {Function=} opt_moar extra setup after called just before
* {@code $replayAll}. See memegen/3437690.
*/
registry.registrar.ConsoleTestUtil.visit = function(
test, opt_args, opt_moar) {
opt_args = opt_args || {};
opt_args.path = opt_args.path || '';
opt_args.testClientId = opt_args.testClientId || 'dummyRegistrarId';
opt_args.testXsrfToken = opt_args.testXsrfToken || 'dummyXsrfToken';
if (opt_args.isEppLoggedIn === undefined) {
opt_args.isEppLoggedIn = true;
}
test.historyMock.$reset();
test.sessionMock.$reset();
test.historyMock.getToken().$returns(opt_args.path).$anyTimes();
test.sessionMock.isEppLoggedIn().$returns(opt_args.isEppLoggedIn).$anyTimes();
test.sessionMock.getClientId().$returns(opt_args.isEppLoggedIn ?
opt_args.testClientId : null).$anyTimes();
if (opt_args.rspXml) {
test.sessionMock
.send(goog.testing.mockmatchers.isString,
goog.testing.mockmatchers.isFunction)
.$does(function(args, cb) {
// XXX: Args should be checked.
var xml = goog.dom.xml.loadXml(opt_args.rspXml);
goog.asserts.assert(xml != null);
cb(registry.xml.convertToJson(xml));
}).$anyTimes();
}
if (opt_moar) {
opt_moar();
}
test.mockControl.$replayAll();
/** @type {!registry.registrar.Console} */
test.console = new registry.registrar.Console(
opt_args.testXsrfToken,
opt_args.testClientId);
// XXX: Should be triggered via event passing.
test.console.handleHashChange();
test.mockControl.$verifyAll();
};

View file

@ -0,0 +1,321 @@
// Copyright 2016 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
goog.setTestOnly();
goog.require('goog.array');
goog.require('goog.dispose');
goog.require('goog.dom');
goog.require('goog.soy');
goog.require('goog.testing.MockControl');
goog.require('goog.testing.PropertyReplacer');
goog.require('goog.testing.asserts');
goog.require('goog.testing.jsunit');
goog.require('goog.testing.net.XhrIo');
goog.require('registry.registrar.ConsoleTestUtil');
goog.require('registry.soy.registrar.console');
goog.require('registry.testing');
goog.require('registry.util');
var $ = goog.dom.getRequiredElement;
var stubs = new goog.testing.PropertyReplacer();
var testContact = null;
var test = {
testXsrfToken: '༼༎෴ ༎༽',
testClientId: 'testClientId',
mockControl: new goog.testing.MockControl()
};
function setUp() {
registry.testing.addToDocument('<div id="test"/>');
registry.testing.addToDocument('<div class="kd-butterbar"/>');
testContact = createTestContact();
goog.soy.renderElement($('test'), registry.soy.registrar.console.main, {
user: {
id: 'test@acme.com',
actionHref: 'blah',
actionName: 'omg'
},
xsrfToken: test.testXsrfToken,
clientId: test.testClientId
});
stubs.setPath('goog.net.XhrIo', goog.testing.net.XhrIo);
registry.registrar.ConsoleTestUtil.setup(test);
}
function tearDown() {
goog.dispose(test.console);
goog.testing.net.XhrIo.cleanup();
stubs.reset();
test.mockControl.$tearDown();
}
function testCollectionView() {
registry.registrar.ConsoleTestUtil.visit(test, {
path: 'contact-settings',
testXsrfToken: test.testXsrfToken,
testClientId: test.testClientId
});
registry.testing.assertReqMockRsp(
test.testXsrfToken,
'/registrar-settings',
{op: 'read', args: {}},
{
status: 'SUCCESS',
message: 'OK',
results: [{
contacts: [testContact]
}]
}
);
assertEquals(1, $('admin-contacts').childNodes.length);
// XXX: Needs more field testing.
}
function testItemView() {
registry.registrar.ConsoleTestUtil.visit(test, {
path: 'contact-settings/test@example.com',
testXsrfToken: test.testXsrfToken,
testClientId: test.testClientId
});
registry.testing.assertReqMockRsp(
test.testXsrfToken,
'/registrar-settings',
{op: 'read', args: {}},
{
status: 'SUCCESS',
message: 'OK',
results: [{
contacts: [testContact]
}]
}
);
assertEquals(testContact.name, $('contacts[0].name').value);
assertEquals(testContact.emailAddress, $('contacts[0].emailAddress').value);
assertEquals(testContact.phoneNumber, $('contacts[0].phoneNumber').value);
assertEquals(testContact.faxNumber, $('contacts[0].faxNumber').value);
// XXX: Types are no longer broken out as individual settings, so relying on
// screenshot test.
}
// XXX: Should be hoisted.
function testItemEditButtons() {
testItemView();
registry.testing.assertVisible($('reg-app-btns-edit'));
registry.testing.assertHidden($('reg-app-btns-save'));
registry.testing.click($('reg-app-btn-edit'));
registry.testing.assertHidden($('reg-app-btns-edit'));
registry.testing.assertVisible($('reg-app-btns-save'));
registry.testing.click($('reg-app-btn-cancel'));
registry.testing.assertVisible($('reg-app-btns-edit'));
registry.testing.assertHidden($('reg-app-btns-save'));
}
function testItemEdit() {
testItemView();
registry.testing.click($('reg-app-btn-edit'));
document.forms.namedItem('item').elements['contacts[0].name'].value = 'bob';
registry.testing.click($('reg-app-btn-save'));
testContact.name = 'bob';
registry.testing.assertReqMockRsp(
test.testXsrfToken,
'/registrar-settings',
{
op: 'update',
args: {
contacts: [testContact],
readonly: false
}
},
{
status: 'SUCCESS',
message: 'OK',
results: [{
contacts: [testContact]
}]
}
);
registry.testing.assertObjectEqualsPretty(
testContact,
simulateJsonForContact(registry.util.parseForm('item').contacts[0]));
}
function testChangeContactTypes() {
testItemView();
registry.testing.click($('reg-app-btn-edit'));
$('contacts[0].type.admin').removeAttribute('checked');
$('contacts[0].type.legal').setAttribute('checked', 'checked');
$('contacts[0].type.marketing').setAttribute('checked', 'checked');
registry.testing.click($('reg-app-btn-save'));
testContact.types = 'LEGAL,MARKETING';
registry.testing.assertReqMockRsp(
test.testXsrfToken,
'/registrar-settings',
{
op: 'update',
args: {
contacts: [testContact],
readonly: false
}
},
{
status: 'SUCCESS',
message: 'OK',
results: [{
contacts: [testContact]
}]
}
);
registry.testing.assertObjectEqualsPretty(
testContact,
simulateJsonForContact(registry.util.parseForm('item').contacts[0]));
}
function testOneOfManyUpdate() {
registry.registrar.ConsoleTestUtil.visit(test, {
path: 'contact-settings/test@example.com',
testXsrfToken: test.testXsrfToken,
testClientId: test.testClientId
});
var testContacts = [
createTestContact('new1@asdf.com'),
testContact,
createTestContact('new2@asdf.com')
];
registry.testing.assertReqMockRsp(
test.testXsrfToken,
'/registrar-settings',
{op: 'read', args: {}},
{
status: 'SUCCESS',
message: 'OK',
results: [{
contacts: testContacts
}]
}
);
// Edit testContact.
registry.testing.click($('reg-app-btn-edit'));
$('contacts[1].type.admin').removeAttribute('checked');
$('contacts[1].type.legal').setAttribute('checked', 'checked');
$('contacts[1].type.marketing').setAttribute('checked', 'checked');
registry.testing.click($('reg-app-btn-save'));
// Should save them all back, with only testContact changed.
testContacts[1].types = 'LEGAL,MARKETING';
registry.testing.assertReqMockRsp(
test.testXsrfToken,
'/registrar-settings',
{op: 'update', args: {contacts: testContacts, readonly: false}},
{
status: 'SUCCESS',
message: 'OK',
results: [{
contacts: testContacts
}]
}
);
}
function testDelete() {
registry.registrar.ConsoleTestUtil.visit(test, {
path: 'contact-settings/test@example.com',
testXsrfToken: test.testXsrfToken,
testClientId: test.testClientId
});
var testContacts = [
createTestContact('new1@asdf.com'),
testContact,
createTestContact('new2@asdf.com')
];
registry.testing.assertReqMockRsp(
test.testXsrfToken,
'/registrar-settings',
{op: 'read', args: {}},
{
status: 'SUCCESS',
message: 'OK',
results: [{
contacts: testContacts
}]
}
);
// Delete testContact.
registry.testing.click($('reg-app-btn-edit'));
registry.testing.click($('reg-app-btn-delete'));
// Should save them all back, with testContact gone.
goog.array.removeAt(testContacts, 1);
registry.testing.assertReqMockRsp(
test.testXsrfToken,
'/registrar-settings',
{op: 'update', args: {contacts: testContacts, readonly: false}},
{
status: 'SUCCESS',
message: 'OK',
results: [{
contacts: testContacts
}]
}
);
}
/**
* @param {string=} opt_email
*/
function createTestContact(opt_email) {
var nameMail = opt_email || 'test@example.com';
return {
name: nameMail,
emailAddress: nameMail,
phoneNumber: '+1.2345551234',
faxNumber: '+1.2345551234',
visibleInWhoisAsAdmin: false,
visibleInWhoisAsTech: false,
types: 'ADMIN'
};
}
/**
* Convert parsed formContact to simulated wire form.
* @param {!Element} contact
*/
function simulateJsonForContact(contact) {
contact.visibleInWhoisAsAdmin = contact.visibleInWhoisAsAdmin == 'true';
contact.visibleInWhoisAsTech = contact.visibleInWhoisAsTech == 'true';
contact.types = '';
for (var tNdx in contact.type) {
if (contact.type[tNdx]) {
if (contact.types.length > 0) {
contact.types += ',';
}
contact.types += ('' + tNdx).toUpperCase();
}
}
delete contact['type'];
return contact;
}

View file

@ -0,0 +1,128 @@
// Copyright 2016 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
goog.setTestOnly();
goog.require('goog.dispose');
goog.require('goog.dom');
goog.require('goog.soy');
goog.require('goog.testing.MockControl');
goog.require('goog.testing.asserts');
goog.require('goog.testing.jsunit');
goog.require('registry.registrar.ConsoleTestUtil');
goog.require('registry.soy.registrar.console');
goog.require('registry.testing');
var $ = goog.dom.getRequiredElement;
var test = {
mockControl: new goog.testing.MockControl()
};
function setUp() {
registry.testing.addToDocument('<div id="test"/>');
registry.testing.addToDocument('<div class="kd-butterbar"/>');
goog.soy.renderElement($('test'), registry.soy.registrar.console.main, {
user: {
id: 'test1.ui@example.com',
actionHref: 'blah'
},
xsrfToken: 'test',
clientId: 'daddy'
});
registry.registrar.ConsoleTestUtil.setup(test);
}
function tearDown() {
goog.dispose(test.console);
test.mockControl.$tearDown();
}
/** Contact hash path should nav to contact page. */
function testVisitContact() {
registry.registrar.ConsoleTestUtil.visit(test, {
path: 'contact/pabloistrad',
rspXml: '<?xml version="1.0"?>' +
'<epp xmlns:domain="urn:ietf:params:xml:ns:domain-1.0"' +
' xmlns:contact="urn:ietf:params:xml:ns:contact-1.0"' +
' xmlns:host="urn:ietf:params:xml:ns:host-1.0"' +
' xmlns:launch="urn:ietf:params:xml:ns:launch-1.0"' +
' xmlns:rgp="urn:ietf:params:xml:ns:rgp-1.0"' +
' xmlns="urn:ietf:params:xml:ns:epp-1.0"' +
' xmlns:secDNS="urn:ietf:params:xml:ns:secDNS-1.1"' +
' xmlns:mark="urn:ietf:params:xml:ns:mark-1.0">' +
' <response>' +
' <result code="1000">' +
' <msg>Command completed successfully</msg>' +
' </result>' +
' <resData>' +
' <contact:infData>' +
' <contact:id>pabloistrad</contact:id>' +
' <contact:roid>1-roid</contact:roid>' +
' <contact:status s="ok"/>' +
' <contact:postalInfo type="int">' +
' <contact:name>name2</contact:name>' +
' <contact:addr>' +
' <contact:street></contact:street>' +
' <contact:city>city2</contact:city>' +
' <contact:cc>US</contact:cc>' +
' </contact:addr>' +
' </contact:postalInfo>' +
' <contact:voice/>' +
' <contact:fax/>' +
' <contact:email>test2.ui@example.com</contact:email>' +
' <contact:clID>daddy</contact:clID>' +
' <contact:crID>daddy</contact:crID>' +
' <contact:crDate>2014-05-06T22:16:36Z</contact:crDate>' +
' <contact:upID>daddy</contact:upID>' +
' <contact:upDate>2014-05-07T16:20:07Z</contact:upDate>' +
' <contact:authInfo>' +
' <contact:pw>asdfasdf</contact:pw>' +
' </contact:authInfo>' +
' </contact:infData>' +
' </resData>' +
' <trID>' +
' <clTRID>abc-1234</clTRID>' +
' <svTRID>c4O3B0pRRKKSrrXsJvxP5w==-2</svTRID>' +
' </trID>' +
' </response>' +
'</epp>'
});
assertEquals(3, $('contact-postalInfo').childNodes.length);
}
/** Contact hash path should nav to contact page. */
function testEdit() {
testVisitContact();
registry.testing.assertVisible($('reg-app-btns-edit'));
registry.testing.click($('reg-app-btn-edit'));
registry.testing.assertHidden($('reg-app-btns-edit'));
registry.testing.assertVisible($('reg-app-btns-save'));
}
/** Contact hash path should nav to contact page. */
function testAddPostalInfo() {
testEdit();
var addPiBtn = $('domain-contact-postalInfo-add-button');
assertNull(addPiBtn.getAttribute('disabled'));
registry.testing.click(addPiBtn);
assertTrue(addPiBtn.hasAttribute('disabled'));
assertEquals(4, $('contact-postalInfo').childNodes.length);
}

View file

@ -0,0 +1,481 @@
// Copyright 2016 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
goog.setTestOnly();
goog.require('goog.History');
goog.require('goog.dispose');
goog.require('goog.dom');
goog.require('goog.soy');
goog.require('goog.testing.MockControl');
goog.require('goog.testing.PropertyReplacer');
goog.require('goog.testing.asserts');
goog.require('goog.testing.jsunit');
goog.require('goog.testing.mockmatchers');
goog.require('goog.testing.net.XhrIo');
goog.require('registry.registrar.Console');
goog.require('registry.soy.registrar.console');
goog.require('registry.testing');
var $ = goog.dom.getRequiredElement;
var _ = goog.testing.mockmatchers.ignoreArgument;
var stubs = new goog.testing.PropertyReplacer();
var mocks = new goog.testing.MockControl();
var historyMock;
var registrarConsole;
function setUp() {
registry.testing.addToDocument('<div id="test"/>');
registry.testing.addToDocument('<div class="kd-butterbar"/>');
goog.soy.renderElement($('test'), registry.soy.registrar.console.main, {
xsrfToken: 'ignore',
clientId: 'ignore',
user: {
id: 'jart@google.com',
actionHref: 'https://justinetunney.com',
actionName: 'gtfo'
}
});
stubs.setPath('goog.net.XhrIo', goog.testing.net.XhrIo);
historyMock = mocks.createStrictMock(goog.History);
mocks.createConstructorMock(goog, 'History')().$returns(historyMock);
historyMock.addEventListener(_, _, _);
historyMock.setEnabled(true);
mocks.$replayAll();
registrarConsole = new registry.registrar.Console('☢', 'jartine');
mocks.$verifyAll();
}
function tearDown() {
goog.dispose(registrarConsole);
stubs.reset();
mocks.$tearDown();
goog.testing.net.XhrIo.cleanup();
}
/** Handles EPP login. */
function handleLogin() {
var request = registry.testing.loadXml(
'<?xml version="1.0"?>' +
'<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">' +
' <command>' +
' <login>' +
' <clID>jartine</clID>' +
' <pw>undefined</pw>' +
' <options>' +
' <version>1.0</version>' +
' <lang>en</lang>' +
' </options>' +
' <svcs>' +
' <objURI>urn:ietf:params:xml:ns:host-1.0</objURI>' +
' <objURI>urn:ietf:params:xml:ns:domain-1.0</objURI>' +
' <objURI>urn:ietf:params:xml:ns:contact-1.0</objURI>' +
' </svcs>' +
' </login>' +
' <clTRID>asdf-1235</clTRID>' +
' </command>' +
'</epp>');
var response = registry.testing.loadXml(
'<?xml version="1.0"?>' +
'<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">' +
' <response>' +
' <result code="2002">' +
' <msg>Registrar is already logged in</msg>' +
' </result>' +
' <trID>' +
' <clTRID>asdf-1235</clTRID>' +
' <svTRID>ytk1RO+8SmaDQxrTIdulnw==-3</svTRID>' +
' </trID>' +
' </response>' +
'</epp>');
var xhr = goog.testing.net.XhrIo.getSendInstances().pop();
assertTrue(xhr.isActive());
assertEquals('/registrar-xhr', xhr.getLastUri());
assertEquals('☢', xhr.getLastRequestHeaders().get('X-CSRF-Token'));
registry.testing.assertXmlEquals(request, xhr.getLastContent());
xhr.simulateResponse(200, response);
}
function testView() {
historyMock.$reset();
historyMock.getToken().$returns('domain/justine.lol').$anyTimes();
mocks.$replayAll();
registrarConsole.handleHashChange();
handleLogin();
var request = registry.testing.loadXml(
'<?xml version="1.0"?>' +
'<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">' +
' <command>' +
' <info>' +
' <domain:info xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">' +
' <domain:name hosts="all">justine.lol</domain:name>' +
' </domain:info>' +
' </info>' +
' <clTRID>abc-1234</clTRID>' +
' </command>' +
'</epp>');
var response = registry.testing.loadXml(
'<?xml version="1.0"?>' +
'<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">' +
' <response>' +
' <result code="1000">' +
' <msg>Command completed successfully</msg>' +
' </result>' +
' <resData>' +
' <domain:infData xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">' +
' <domain:name>justine.lol</domain:name>' +
' <domain:roid>6-roid</domain:roid>' +
' <domain:status s="inactive"/>' +
' <domain:registrant>GK Chesterton</domain:registrant>' +
' <domain:contact type="admin">&lt;justine&gt;</domain:contact>' +
' <domain:contact type="billing">candycrush</domain:contact>' +
' <domain:contact type="tech">krieger</domain:contact>' +
' <domain:ns>' +
' <domain:hostObj>ns1.justine.lol</domain:hostObj>' +
' <domain:hostObj>ns2.justine.lol</domain:hostObj>' +
' </domain:ns>' +
' <domain:host>ns1.justine.lol</domain:host>' +
' <domain:clID>justine</domain:clID>' +
' <domain:crID>justine</domain:crID>' +
' <domain:crDate>2014-07-10T02:17:02Z</domain:crDate>' +
' <domain:exDate>2015-07-10T02:17:02Z</domain:exDate>' +
' <domain:authInfo>' +
' <domain:pw>lolcat</domain:pw>' +
' </domain:authInfo>' +
' </domain:infData>' +
' </resData>' +
' <trID>' +
' <clTRID>abc-1234</clTRID>' +
' <svTRID>ytk1RO+8SmaDQxrTIdulnw==-4</svTRID>' +
' </trID>' +
' </response>' +
'</epp>');
var xhr = goog.testing.net.XhrIo.getSendInstances().pop();
assertTrue('XHR is inactive.', xhr.isActive());
assertEquals('/registrar-xhr', xhr.getLastUri());
assertEquals('☢', xhr.getLastRequestHeaders().get('X-CSRF-Token'));
registry.testing.assertXmlEquals(request, xhr.getLastContent());
xhr.simulateResponse(200, response);
assertEquals('We require more vespene gas.',
0, goog.testing.net.XhrIo.getSendInstances().length);
mocks.$verifyAll();
assertTrue('Form should be read-only.', $('domain:exDate').readOnly);
assertContains('justine.lol', $('reg-content').innerHTML);
assertEquals('2015-07-10T02:17:02Z', $('domain:exDate').value);
assertEquals('GK Chesterton', $('domain:registrant').value);
assertEquals('<justine>', $('domain:contact[0].value').value);
assertEquals('candycrush', $('domain:contact[1].value').value);
assertEquals('krieger', $('domain:contact[2].value').value);
assertEquals('lolcat', $('domain:authInfo.domain:pw').value);
assertEquals('ns1.justine.lol', $('domain:ns.domain:hostObj[0].value').value);
assertEquals('ns2.justine.lol', $('domain:ns.domain:hostObj[1].value').value);
}
function testEdit() {
testView();
historyMock.$reset();
mocks.$replayAll();
registry.testing.click($('reg-app-btn-edit'));
assertFalse('Form should be edible.', $('domain:exDate').readOnly);
$('domain:registrant').value = 'Jonathan Swift';
$('domain:authInfo.domain:pw').value = '(✿◕‿◕)';
registry.testing.click($('reg-app-btn-save'));
var request = registry.testing.loadXml(
'<?xml version="1.0"?>' +
'<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">' +
' <command>' +
' <update>' +
' <domain:update xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">' +
' <domain:name>justine.lol</domain:name>' +
' <domain:chg>' +
' <domain:registrant>Jonathan Swift</domain:registrant>' +
' <domain:authInfo>' +
' <domain:pw>(✿◕‿◕)</domain:pw>' +
' </domain:authInfo>' +
' </domain:chg>' +
' </domain:update>' +
' </update>' +
' <clTRID>abc-1234</clTRID>' +
' </command>' +
'</epp>');
var response = registry.testing.loadXml(
'<?xml version="1.0"?>' +
'<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">' +
' <response>' +
' <result code="1000">' +
' <msg>This world is built from a million lies.</msg>' +
' </result>' +
' <trID>' +
' <clTRID>abc-1234</clTRID>' +
' <svTRID>214CjbYuTsijoP8sgyFUNg==-e</svTRID>' +
' </trID>' +
' </response>' +
'</epp>');
var xhr = goog.testing.net.XhrIo.getSendInstances().pop();
assertTrue('XHR is inactive.', xhr.isActive());
assertEquals('/registrar-xhr', xhr.getLastUri());
assertEquals('☢', xhr.getLastRequestHeaders().get('X-CSRF-Token'));
registry.testing.assertXmlEquals(request, xhr.getLastContent());
xhr.simulateResponse(200, response);
request = registry.testing.loadXml(
'<?xml version="1.0"?>' +
'<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">' +
' <command>' +
' <info>' +
' <domain:info xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">' +
' <domain:name hosts="all">justine.lol</domain:name>' +
' </domain:info>' +
' </info>' +
' <clTRID>abc-1234</clTRID>' +
' </command>' +
'</epp>');
response = registry.testing.loadXml(
'<?xml version="1.0"?>' +
'<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">' +
' <response>' +
' <result code="1000">' +
' <msg>How can we live in the land of the dead?</msg>' +
' </result>' +
' <resData>' +
' <domain:infData xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">' +
' <domain:name>justine.lol</domain:name>' +
' <domain:roid>6-roid</domain:roid>' +
' <domain:status s="inactive"/>' +
' <domain:registrant>Jonathan Swift</domain:registrant>' +
' <domain:contact type="admin">&lt;justine&gt;</domain:contact>' +
' <domain:contact type="billing">candycrush</domain:contact>' +
' <domain:contact type="tech">krieger</domain:contact>' +
' <domain:ns>' +
' <domain:hostObj>ns1.justine.lol</domain:hostObj>' +
' <domain:hostObj>ns2.justine.lol</domain:hostObj>' +
' </domain:ns>' +
' <domain:host>ns1.justine.lol</domain:host>' +
' <domain:clID>justine</domain:clID>' +
' <domain:crID>justine</domain:crID>' +
' <domain:crDate>2014-07-10T02:17:02Z</domain:crDate>' +
' <domain:exDate>2015-07-10T02:17:02Z</domain:exDate>' +
' <domain:authInfo>' +
' <domain:pw>(✿◕‿◕)</domain:pw>' +
' </domain:authInfo>' +
' </domain:infData>' +
' </resData>' +
' <trID>' +
' <clTRID>abc-1234</clTRID>' +
' <svTRID>ytk1RO+8SmaDQxrTIdulnw==-4</svTRID>' +
' </trID>' +
' </response>' +
'</epp>');
xhr = goog.testing.net.XhrIo.getSendInstances().pop();
assertTrue('XHR is inactive.', xhr.isActive());
assertEquals('/registrar-xhr', xhr.getLastUri());
assertEquals('☢', xhr.getLastRequestHeaders().get('X-CSRF-Token'));
registry.testing.assertXmlEquals(request, xhr.getLastContent());
xhr.simulateResponse(200, response);
assertEquals('We require more vespene gas.',
0, goog.testing.net.XhrIo.getSendInstances().length);
mocks.$verifyAll();
assertTrue($('domain:exDate').readOnly);
assertContains('justine.lol', $('reg-content').innerHTML);
assertEquals('2015-07-10T02:17:02Z', $('domain:exDate').value);
assertEquals('Jonathan Swift', $('domain:registrant').value);
assertEquals('<justine>', $('domain:contact[0].value').value);
assertEquals('candycrush', $('domain:contact[1].value').value);
assertEquals('krieger', $('domain:contact[2].value').value);
assertEquals('(✿◕‿◕)', $('domain:authInfo.domain:pw').value);
assertEquals('ns1.justine.lol', $('domain:ns.domain:hostObj[0].value').value);
assertEquals('ns2.justine.lol', $('domain:ns.domain:hostObj[1].value').value);
}
function testEdit_cancel_restoresOriginalValues() {
testView();
registry.testing.click($('reg-app-btn-edit'));
assertFalse('Form should be edible.', $('domain:exDate').readOnly);
$('domain:registrant').value = 'Jonathan Swift';
$('domain:authInfo.domain:pw').value = '(✿◕‿◕)';
registry.testing.click($('reg-app-btn-cancel'));
assertTrue('Form should be read-only.', $('domain:exDate').readOnly);
assertEquals('GK Chesterton', $('domain:registrant').value);
assertEquals('lolcat', $('domain:authInfo.domain:pw').value);
}
function testCreate() {
historyMock.$reset();
historyMock.getToken().$returns('domain').$anyTimes();
mocks.$replayAll();
registrarConsole.handleHashChange();
handleLogin();
mocks.$verifyAll();
assertFalse('Form should be edible.', $('domain:name').readOnly);
$('domain:name').value = 'bog.lol';
$('domain:period').value = '1';
$('domain:authInfo.domain:pw').value = 'attorney at lawl';
$('domain:registrant').value = 'Chris Pohl';
registry.testing.click($('domain-contact-add-button'));
$('domain:contact[0].value').value = 'BlutEngel';
$('domain:contact[0].@type').value = 'admin';
registry.testing.click($('domain-contact-add-button'));
$('domain:contact[1].value').value = 'Ravenous';
$('domain:contact[1].@type').value = 'tech';
registry.testing.click($('domain-contact-add-button'));
$('domain:contact[2].value').value = 'Dark Angels';
$('domain:contact[2].@type').value = 'billing';
historyMock.$reset();
mocks.$replayAll();
registry.testing.click($('reg-app-btn-save'));
var request = registry.testing.loadXml(
'<?xml version="1.0"?>' +
'<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">' +
' <command>' +
' <create>' +
' <domain:create xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">' +
' <domain:name>bog.lol</domain:name>' +
' <domain:period unit="y">1</domain:period>' +
' <domain:registrant>Chris Pohl</domain:registrant>' +
' <domain:contact type="admin">BlutEngel</domain:contact>' +
' <domain:contact type="tech">Ravenous</domain:contact>' +
' <domain:contact type="billing">Dark Angels</domain:contact>' +
' <domain:authInfo>' +
' <domain:pw>attorney at lawl</domain:pw>' +
' </domain:authInfo>' +
' </domain:create>' +
' </create>' +
' <clTRID>abc-1234</clTRID>' +
' </command>' +
'</epp>');
var response = registry.testing.loadXml(
'<?xml version="1.0"?>' +
'<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">' +
' <response>' +
' <result code="1000">' +
' <msg>Command completed successfully</msg>' +
' </result>' +
' <resData>' +
' <domain:creData xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">' +
' <domain:name>bog.lol</domain:name>' +
' <domain:crDate>2014-07-17T08:19:24Z</domain:crDate>' +
' <domain:exDate>2015-07-17T08:19:24Z</domain:exDate>' +
' </domain:creData>' +
' </resData>' +
' <trID>' +
' <clTRID>abc-1234</clTRID>' +
' <svTRID>OBPI6JvEQfOUaO8qGf+IKA==-7</svTRID>' +
' </trID>' +
' </response>' +
'</epp>');
var xhr = goog.testing.net.XhrIo.getSendInstances().pop();
assertTrue('XHR is inactive.', xhr.isActive());
assertEquals('/registrar-xhr', xhr.getLastUri());
assertEquals('☢', xhr.getLastRequestHeaders().get('X-CSRF-Token'));
registry.testing.assertXmlEquals(request, xhr.getLastContent());
xhr.simulateResponse(200, response);
request = registry.testing.loadXml(
'<?xml version="1.0"?>' +
'<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">' +
' <command>' +
' <info>' +
' <domain:info xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">' +
' <domain:name hosts="all">bog.lol</domain:name>' +
' </domain:info>' +
' </info>' +
' <clTRID>abc-1234</clTRID>' +
' </command>' +
'</epp>');
response = registry.testing.loadXml(
'<?xml version="1.0"?>' +
'<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">' +
' <response>' +
' <result code="1000">' +
' <msg>Command completed successfully</msg>' +
' </result>' +
' <resData>' +
' <domain:infData xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">' +
' <domain:name>bog.lol</domain:name>' +
' <domain:roid>1f-roid</domain:roid>' +
' <domain:status s="inactive"/>' +
' <domain:registrant>Chris Pohl</domain:registrant>' +
' <domain:contact type="admin">BlutEngel</domain:contact>' +
' <domain:contact type="tech">Ravenous</domain:contact>' +
' <domain:contact type="billing">Dark Angels</domain:contact>' +
' <domain:clID>justine</domain:clID>' +
' <domain:crID>justine</domain:crID>' +
' <domain:crDate>2014-07-17T08:19:24Z</domain:crDate>' +
' <domain:exDate>2015-07-17T08:19:24Z</domain:exDate>' +
' <domain:authInfo>' +
' <domain:pw>attorney at lawl</domain:pw>' +
' </domain:authInfo>' +
' </domain:infData>' +
' </resData>' +
' <extension>' +
' <rgp:infData xmlns:rgp="urn:ietf:params:xml:ns:rgp-1.0">' +
' <rgp:rgpStatus s="addPeriod"/>' +
' </rgp:infData>' +
' </extension>' +
' <trID>' +
' <clTRID>abc-1234</clTRID>' +
' <svTRID>OBPI6JvEQfOUaO8qGf+IKA==-8</svTRID>' +
' </trID>' +
' </response>' +
'</epp>');
xhr = goog.testing.net.XhrIo.getSendInstances().pop();
assertTrue('XHR is inactive.', xhr.isActive());
assertEquals('/registrar-xhr', xhr.getLastUri());
assertEquals('☢', xhr.getLastRequestHeaders().get('X-CSRF-Token'));
registry.testing.assertXmlEquals(request, xhr.getLastContent());
xhr.simulateResponse(200, response);
assertEquals('We require more vespene gas.',
0, goog.testing.net.XhrIo.getSendInstances().length);
mocks.$verifyAll();
assertTrue('Form should be read-only.', $('domain:exDate').readOnly);
assertContains('bog.lol', $('reg-content').innerHTML);
assertEquals('2015-07-17T08:19:24Z', $('domain:exDate').value);
assertEquals('Chris Pohl', $('domain:registrant').value);
assertEquals('BlutEngel', $('domain:contact[0].value').value);
assertEquals('Ravenous', $('domain:contact[1].value').value);
assertEquals('Dark Angels', $('domain:contact[2].value').value);
assertEquals('attorney at lawl', $('domain:authInfo.domain:pw').value);
assertNull(goog.dom.getElement('domain:ns.domain:hostObj[0].value'));
}

View file

@ -0,0 +1,421 @@
// Copyright 2016 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
goog.setTestOnly();
goog.require('goog.History');
goog.require('goog.dispose');
goog.require('goog.dom');
goog.require('goog.soy');
goog.require('goog.testing.MockControl');
goog.require('goog.testing.PropertyReplacer');
goog.require('goog.testing.asserts');
goog.require('goog.testing.jsunit');
goog.require('goog.testing.mockmatchers');
goog.require('goog.testing.net.XhrIo');
goog.require('registry.registrar.Console');
goog.require('registry.soy.registrar.console');
goog.require('registry.testing');
var $ = goog.dom.getRequiredElement;
var _ = goog.testing.mockmatchers.ignoreArgument;
var stubs = new goog.testing.PropertyReplacer();
var mocks = new goog.testing.MockControl();
var historyMock;
var registrarConsole;
function setUp() {
registry.testing.addToDocument('<div id="test"/>');
registry.testing.addToDocument('<div class="kd-butterbar"/>');
goog.soy.renderElement($('test'), registry.soy.registrar.console.main, {
xsrfToken: 'ignore',
clientId: 'ignore',
user: {
id: 'test2.ui@example.com',
actionHref: 'https://example.com',
actionName: 'gtfo'
}
});
stubs.setPath('goog.net.XhrIo', goog.testing.net.XhrIo);
historyMock = mocks.createStrictMock(goog.History);
mocks.createConstructorMock(goog, 'History')().$returns(historyMock);
historyMock.addEventListener(_, _, _);
historyMock.setEnabled(true);
mocks.$replayAll();
registrarConsole = new registry.registrar.Console('☢', 'jartine');
mocks.$verifyAll();
}
function tearDown() {
goog.dispose(registrarConsole);
stubs.reset();
mocks.$tearDown();
goog.testing.net.XhrIo.cleanup();
}
/** Handles EPP login. */
function handleLogin() {
var request = registry.testing.loadXml(
'<?xml version="1.0"?>' +
'<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">' +
' <command>' +
' <login>' +
' <clID>jartine</clID>' +
' <pw>undefined</pw>' +
' <options>' +
' <version>1.0</version>' +
' <lang>en</lang>' +
' </options>' +
' <svcs>' +
' <objURI>urn:ietf:params:xml:ns:host-1.0</objURI>' +
' <objURI>urn:ietf:params:xml:ns:domain-1.0</objURI>' +
' <objURI>urn:ietf:params:xml:ns:contact-1.0</objURI>' +
' </svcs>' +
' </login>' +
' <clTRID>asdf-1235</clTRID>' +
' </command>' +
'</epp>');
var response = registry.testing.loadXml(
'<?xml version="1.0"?>' +
'<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">' +
' <response>' +
' <result code="2002">' +
' <msg>Registrar is already logged in</msg>' +
' </result>' +
' <trID>' +
' <clTRID>asdf-1235</clTRID>' +
' <svTRID>ytk1RO+8SmaDQxrTIdulnw==-3</svTRID>' +
' </trID>' +
' </response>' +
'</epp>');
var xhr = goog.testing.net.XhrIo.getSendInstances().pop();
assertTrue(xhr.isActive());
assertEquals('/registrar-xhr', xhr.getLastUri());
assertEquals('☢', xhr.getLastRequestHeaders().get('X-CSRF-Token'));
registry.testing.assertXmlEquals(request, xhr.getLastContent());
xhr.simulateResponse(200, response);
}
function testView() {
historyMock.$reset();
historyMock.getToken().$returns('host/ns1.justine.lol').$anyTimes();
mocks.$replayAll();
registrarConsole.handleHashChange();
handleLogin();
var request = registry.testing.loadXml(
'<?xml version="1.0"?>' +
'<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">' +
' <command>' +
' <info>' +
' <host:info xmlns:host="urn:ietf:params:xml:ns:host-1.0">' +
' <host:name>ns1.justine.lol</host:name>' +
' </host:info>' +
' </info>' +
' <clTRID>abc-1234</clTRID>' +
' </command>' +
'</epp>');
var response = registry.testing.loadXml(
'<?xml version="1.0"?>' +
'<epp xmlns="urn:ietf:params:xml:ns:epp-1.0"' +
' xmlns:host="urn:ietf:params:xml:ns:host-1.0">' +
' <response>' +
' <result code="1000">' +
' <msg>Command completed successfully</msg>' +
' </result>' +
' <resData>' +
' <host:infData>' +
' <host:name>ns1.justine.lol</host:name>' +
' <host:roid>8-roid</host:roid>' +
' <host:status s="ok"/>' +
' <host:addr ip="v4">8.8.8.8</host:addr>' +
' <host:addr ip="v6">feed:a:bee::1</host:addr>' +
' <host:clID>justine</host:clID>' +
' <host:crID>justine</host:crID>' +
' <host:crDate>2014-07-10T02:18:34Z</host:crDate>' +
' </host:infData>' +
' </resData>' +
' <trID>' +
' <clTRID>abc-1234</clTRID>' +
' <svTRID>EweBEzCZTJirOqRmrtYrAA==-b</svTRID>' +
' </trID>' +
' </response>' +
'</epp>');
var xhr = goog.testing.net.XhrIo.getSendInstances().pop();
assertTrue('XHR is inactive.', xhr.isActive());
assertEquals('/registrar-xhr', xhr.getLastUri());
assertEquals('application/epp+xml',
xhr.getLastRequestHeaders().get('Content-Type'));
assertEquals('☢', xhr.getLastRequestHeaders().get('X-CSRF-Token'));
registry.testing.assertXmlEquals(request, xhr.getLastContent());
xhr.simulateResponse(200, response);
assertEquals('We require more vespene gas.',
0, goog.testing.net.XhrIo.getSendInstances().length);
mocks.$verifyAll();
assertTrue('Form should be read-only.', $('host:chgName').readOnly);
assertContains('ns1.justine.lol', $('reg-content').innerHTML);
assertEquals('ns1.justine.lol', $('host:chgName').value);
assertEquals('8.8.8.8', $('host:addr[0].value').value);
assertEquals('feed:a:bee::1', $('host:addr[1].value').value);
}
function testEditFirstAddr_ignoreSecond_addThird() {
testView();
historyMock.$reset();
mocks.$replayAll();
registry.testing.click($('reg-app-btn-edit'));
assertFalse('Form should be edible.', $('host:addr[0].value').readOnly);
$('host:addr[0].value').value = '1.2.3.4';
registry.testing.click($('domain-host-addr-add-button'));
$('host:addr[2].value').value = 'feed:a:fed::1';
registry.testing.click($('reg-app-btn-save'));
var request = registry.testing.loadXml(
'<?xml version="1.0"?>' +
'<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">' +
' <command>' +
' <update>' +
' <host:update xmlns:host="urn:ietf:params:xml:ns:host-1.0">' +
' <host:name>ns1.justine.lol</host:name>' +
' <host:add>' +
' <host:addr ip="v4">1.2.3.4</host:addr>' +
' <host:addr ip="v6">feed:a:fed::1</host:addr>' +
' </host:add>' +
' <host:rem>' +
' <host:addr ip="v4">8.8.8.8</host:addr>' +
' </host:rem>' +
' </host:update>' +
' </update>' +
' <clTRID>abc-1234</clTRID>' +
' </command>' +
'</epp>');
var response = registry.testing.loadXml(
'<?xml version="1.0"?>' +
'<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">' +
' <response>' +
' <result code="1000">' +
' <msg>This world is built from a million lies.</msg>' +
' </result>' +
' <trID>' +
' <clTRID>abc-1234</clTRID>' +
' <svTRID>214CjbYuTsijoP8sgyFUNg==-e</svTRID>' +
' </trID>' +
' </response>' +
'</epp>');
var xhr = goog.testing.net.XhrIo.getSendInstances().pop();
assertTrue('XHR is inactive.', xhr.isActive());
assertEquals('/registrar-xhr', xhr.getLastUri());
assertEquals('☢', xhr.getLastRequestHeaders().get('X-CSRF-Token'));
registry.testing.assertXmlEquals(request, xhr.getLastContent());
xhr.simulateResponse(200, response);
request = registry.testing.loadXml(
'<?xml version="1.0"?>' +
'<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">' +
' <command>' +
' <info>' +
' <host:info xmlns:host="urn:ietf:params:xml:ns:host-1.0">' +
' <host:name>ns1.justine.lol</host:name>' +
' </host:info>' +
' </info>' +
' <clTRID>abc-1234</clTRID>' +
' </command>' +
'</epp>');
response = registry.testing.loadXml(
'<?xml version="1.0"?>' +
'<epp xmlns="urn:ietf:params:xml:ns:epp-1.0"' +
' xmlns:host="urn:ietf:params:xml:ns:host-1.0">' +
' <response>' +
' <result code="1000">' +
' <msg>Command completed successfully</msg>' +
' </result>' +
' <resData>' +
' <host:infData>' +
' <host:name>ns1.justine.lol</host:name>' +
' <host:roid>8-roid</host:roid>' +
' <host:status s="ok"/>' +
' <host:addr ip="v6">feed:a:bee::1</host:addr>' +
' <host:addr ip="v4">1.2.3.4</host:addr>' +
' <host:addr ip="v6">feed:a:fed::1</host:addr>' +
' <host:clID>justine</host:clID>' +
' <host:crID>justine</host:crID>' +
' <host:crDate>2014-07-10T02:18:34Z</host:crDate>' +
' </host:infData>' +
' </resData>' +
' <trID>' +
' <clTRID>abc-1234</clTRID>' +
' <svTRID>EweBEzCZTJirOqRmrtYrAA==-b</svTRID>' +
' </trID>' +
' </response>' +
'</epp>');
xhr = goog.testing.net.XhrIo.getSendInstances().pop();
assertTrue('XHR is inactive.', xhr.isActive());
assertEquals('/registrar-xhr', xhr.getLastUri());
assertEquals('☢', xhr.getLastRequestHeaders().get('X-CSRF-Token'));
registry.testing.assertXmlEquals(request, xhr.getLastContent());
xhr.simulateResponse(200, response);
assertEquals('We require more vespene gas.',
0, goog.testing.net.XhrIo.getSendInstances().length);
mocks.$verifyAll();
assertTrue('Form should be read-only.', $('host:chgName').readOnly);
assertContains('ns1.justine.lol', $('reg-content').innerHTML);
assertEquals('ns1.justine.lol', $('host:chgName').value);
assertEquals('feed:a:bee::1', $('host:addr[0].value').value);
assertEquals('1.2.3.4', $('host:addr[1].value').value);
assertEquals('feed:a:fed::1', $('host:addr[2].value').value);
}
function testCreate() {
historyMock.$reset();
historyMock.getToken().$returns('host').$anyTimes();
mocks.$replayAll();
registrarConsole.handleHashChange();
handleLogin();
mocks.$verifyAll();
assertFalse('Form should be edible.', $('host:name').readOnly);
$('host:name').value = 'ns1.example.tld';
registry.testing.click($('domain-host-addr-add-button'));
$('host:addr[0].value').value = '192.0.2.2';
registry.testing.click($('domain-host-addr-add-button'));
$('host:addr[1].value').value = '192.0.2.29';
registry.testing.click($('domain-host-addr-add-button'));
$('host:addr[2].value').value = '1080:0:0:0:8:800:200C:417A';
historyMock.$reset();
mocks.$replayAll();
registry.testing.click($('reg-app-btn-save'));
var request = registry.testing.loadXml(
'<?xml version="1.0"?>' +
'<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">' +
' <command>' +
' <create>' +
' <host:create xmlns:host="urn:ietf:params:xml:ns:host-1.0">' +
' <host:name>ns1.example.tld</host:name>' +
' <host:addr ip="v4">192.0.2.2</host:addr>' +
' <host:addr ip="v4">192.0.2.29</host:addr>' +
' <host:addr ip="v6">1080:0:0:0:8:800:200C:417A</host:addr>' +
' </host:create>' +
' </create>' +
' <clTRID>abc-1234</clTRID>' +
' </command>' +
'</epp>');
var response = registry.testing.loadXml(
'<?xml version="1.0"?>' +
'<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">' +
' <response>' +
' <result code="1000">' +
' <msg>Command completed successfully</msg>' +
' </result>' +
' <resData>' +
' <host:creData xmlns:host="urn:ietf:params:xml:ns:host-1.0">' +
' <host:name>ns1.example.tld</host:name>' +
' <host:crDate>1999-04-03T22:00:00.0Z</host:crDate>' +
' </host:creData>' +
' </resData>' +
' <trID>' +
' <clTRID>abc-1234</clTRID>' +
' <svTRID>EweBEzCZTJirOqRmrtYrAA==-b</svTRID>' +
' </trID>' +
' </response>' +
'</epp>');
var xhr = goog.testing.net.XhrIo.getSendInstances().pop();
assertTrue('XHR is inactive.', xhr.isActive());
assertEquals('/registrar-xhr', xhr.getLastUri());
assertEquals('☢', xhr.getLastRequestHeaders().get('X-CSRF-Token'));
registry.testing.assertXmlEquals(request, xhr.getLastContent());
xhr.simulateResponse(200, response);
request = registry.testing.loadXml(
'<?xml version="1.0"?>' +
'<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">' +
' <command>' +
' <info>' +
' <host:info xmlns:host="urn:ietf:params:xml:ns:host-1.0">' +
' <host:name>ns1.example.tld</host:name>' +
' </host:info>' +
' </info>' +
' <clTRID>abc-1234</clTRID>' +
' </command>' +
'</epp>');
response = registry.testing.loadXml(
'<?xml version="1.0"?>' +
'<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">' +
' <response>' +
' <result code="1000">' +
' <msg>Command completed successfully</msg>' +
' </result>' +
' <resData>' +
' <host:infData xmlns:host="urn:ietf:params:xml:ns:host-1.0">' +
' <host:name>ns1.example.tld</host:name>' +
' <host:roid>NS1_EXAMPLE1-REP</host:roid>' +
' <host:status s="linked"/>' +
' <host:status s="clientUpdateProhibited"/>' +
' <host:addr ip="v4">192.0.2.2</host:addr>' +
' <host:addr ip="v4">192.0.2.29</host:addr>' +
' <host:addr ip="v6">1080:0:0:0:8:800:200C:417A</host:addr>' +
' <host:clID>TheRegistrar</host:clID>' +
' <host:crID>NewRegistrar</host:crID>' +
' <host:crDate>1999-04-03T22:00:00.0Z</host:crDate>' +
' <host:upID>NewRegistrar</host:upID>' +
' <host:upDate>1999-12-03T09:00:00.0Z</host:upDate>' +
' <host:trDate>2000-04-08T09:00:00.0Z</host:trDate>' +
' </host:infData>' +
' </resData>' +
' <trID>' +
' <clTRID>abc-1234</clTRID>' +
' <svTRID>EweBEzCZTJirOqRmrtYrAA==-b</svTRID>' +
' </trID>' +
' </response>' +
'</epp>');
xhr = goog.testing.net.XhrIo.getSendInstances().pop();
assertTrue('XHR is inactive.', xhr.isActive());
assertEquals('/registrar-xhr', xhr.getLastUri());
assertEquals('☢', xhr.getLastRequestHeaders().get('X-CSRF-Token'));
registry.testing.assertXmlEquals(request, xhr.getLastContent());
xhr.simulateResponse(200, response);
assertEquals('We require more vespene gas.',
0, goog.testing.net.XhrIo.getSendInstances().length);
mocks.$verifyAll();
assertTrue('Form should be read-only.', $('host:chgName').readOnly);
assertEquals('ns1.example.tld', $('host:chgName').value);
assertEquals('192.0.2.2', $('host:addr[0].value').value);
assertEquals('192.0.2.29', $('host:addr[1].value').value);
assertEquals('1080:0:0:0:8:800:200C:417A', $('host:addr[2].value').value);
}

View file

@ -0,0 +1,222 @@
// Copyright 2016 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
goog.setTestOnly();
goog.require('goog.dispose');
goog.require('goog.dom');
goog.require('goog.dom.classlist');
goog.require('goog.events.EventType');
goog.require('goog.json');
goog.require('goog.testing.PropertyReplacer');
goog.require('goog.testing.asserts');
goog.require('goog.testing.events');
goog.require('goog.testing.events.Event');
goog.require('goog.testing.jsunit');
goog.require('goog.testing.net.XhrIo');
goog.require('registry.registrar.Payment');
goog.require('registry.testing');
var $ = goog.dom.getRequiredElement;
var $$ = goog.dom.getRequiredElementByClass;
var stubs = new goog.testing.PropertyReplacer();
var page;
function setUp() {
registry.testing.addToDocument('<div id="reg-content"></div>');
registry.testing.addToDocument('<div class="kd-butterbar"></div>');
registry.testing.addToDocument('<div class="kd-butterbar-text"></div>');
stubs.setPath('goog.net.XhrIo', goog.testing.net.XhrIo);
page = new registry.registrar.Payment(null, '?');
page.bindToDom();
}
function tearDown() {
goog.dispose(page);
stubs.reset();
goog.testing.net.XhrIo.cleanup();
}
function testSandbox_showsDisabled() {
registry.testing.assertReqMockRsp(
'?',
'/registrar-payment-setup',
{},
{
status: 'ERROR',
message: 'sandbox'
});
assertContains('Payment Page Disabled',
goog.dom.getTextContent($$('reg-payment')));
}
function testRenderForm() {
registry.testing.assertReqMockRsp(
'?',
'/registrar-payment-setup',
{},
{
status: 'SUCCESS',
results: [
{
token: 'omg-im-a-token',
currencies: ['LOL', 'OMG'],
brainframe: ''
}
]
});
assertEquals('', $('amount').value);
assertEquals('LOL', goog.dom.getTextContent($$('selected', $('currency'))));
assertTrue(
goog.dom.classlist.contains($$('reg-payment-form-submit'), 'disabled'));
}
function testResize() {
testRenderForm();
send({
type: 'resize_request',
height: 123
});
assertEquals('123', $$('reg-payment-form-method').height);
}
function testReady() {
testRenderForm();
send({type: 'ready'});
assertFalse(
goog.dom.classlist.contains($$('reg-payment-form-submit'), 'disabled'));
}
function testPaymentMethodCard() {
testRenderForm();
send({
type: 'payment_method',
method: {
type: 'CreditCard',
nonce: 'omg-im-a-nonce',
details: {
cardType: 'Amex',
lastTwo: '12'
}
}
});
assertEquals(
'American Express: xxxx xxxxxx xxx12',
goog.dom.getTextContent($$('reg-payment-form-method-info')));
}
function testPaymentMethodPaypal() {
testRenderForm();
send({
type: 'payment_method',
method: {
type: 'PayPalAccount',
nonce: 'omg-im-a-nonce',
details: {
email: 'sparrows@nightingales.example'
}
}
});
assertEquals(
'PayPal: sparrows@nightingales.example',
goog.dom.getTextContent($$('reg-payment-form-method-info')));
}
function testBadAmount_displaysError() {
testPaymentMethodCard();
$('amount').value = '3.14';
submit();
registry.testing.assertReqMockRsp(
'?',
'/registrar-payment',
{
amount: '3.14',
currency: 'LOL',
paymentMethodNonce: 'omg-im-a-nonce'
},
{
status: 'ERROR',
message: 'gimmeh moar money',
field: 'amount'
});
assertTrue(goog.dom.classlist.contains($('amount'), 'kd-formerror'));
assertEquals('gimmeh moar money',
goog.dom.getTextContent($$('kd-errormessage')));
}
function testGoodPayment_displaysSuccessPage() {
testPaymentMethodCard();
$('amount').value = '314';
submit();
registry.testing.assertReqMockRsp(
'?',
'/registrar-payment',
{
amount: '314',
currency: 'LOL',
paymentMethodNonce: 'omg-im-a-nonce'
},
{
status: 'SUCCESS',
results: [
{
id: 'omg-im-an-id',
formattedAmount: '$314'
}
]
});
assertContains('Payment Processed',
goog.dom.getTextContent($$('reg-payment')));
assertContains('omg-im-an-id',
goog.dom.getTextContent($$('reg-payment')));
assertContains('$314',
goog.dom.getTextContent($$('reg-payment')));
}
/**
* Sends message to page.
* @param {string} message
*/
function send(message) {
page.onMessage_({
getBrowserEvent: function() {
return {
source: goog.dom.getFrameContentWindow($$('reg-payment-form-method')),
data: goog.json.serialize(message)
};
}
});
}
/** Submits payment form. */
function submit() {
goog.testing.events.fireBrowserEvent(
new goog.testing.events.Event(
goog.events.EventType.SUBMIT,
$$('reg-payment-form')));
}

View file

@ -0,0 +1,143 @@
// Copyright 2016 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
goog.setTestOnly();
goog.require('goog.dispose');
goog.require('goog.dom');
goog.require('goog.soy');
goog.require('goog.testing.MockControl');
goog.require('goog.testing.PropertyReplacer');
goog.require('goog.testing.asserts');
goog.require('goog.testing.jsunit');
goog.require('goog.testing.net.XhrIo');
goog.require('registry.registrar.ConsoleTestUtil');
goog.require('registry.soy.registrar.console');
goog.require('registry.testing');
goog.require('registry.util');
var $ = goog.dom.getRequiredElement;
var stubs = new goog.testing.PropertyReplacer();
var expectedRegistrar = {
ipAddressWhitelist: [],
phonePasscode: '12345',
clientCertificate: null,
clientCertificateHash: null,
failoverClientCertificate: null
};
var test = {
testXsrfToken: '༼༎෴ ༎༽',
testClientId: 'testClientId',
mockControl: new goog.testing.MockControl()
};
function setUp() {
registry.testing.addToDocument('<div id="test"/>');
registry.testing.addToDocument('<div class="kd-butterbar"/>');
goog.soy.renderElement($('test'), registry.soy.registrar.console.main, {
user: {
id: 'test@acme.com',
actionHref: 'blah',
actionName: 'omg'
},
xsrfToken: test.testXsrfToken,
clientId: test.testClientId
});
stubs.setPath('goog.net.XhrIo', goog.testing.net.XhrIo);
registry.registrar.ConsoleTestUtil.setup(test);
}
function tearDown() {
goog.dispose(test.console);
goog.testing.net.XhrIo.cleanup();
stubs.reset();
test.mockControl.$tearDown();
}
function testView() {
registry.registrar.ConsoleTestUtil.visit(test, {
path: 'security-settings',
testXsrfToken: test.testXsrfToken,
testClientId: test.testClientId
});
registry.testing.assertReqMockRsp(
test.testXsrfToken,
'/registrar-settings',
{op: 'read', args: {}},
{
status: 'SUCCESS',
message: 'OK',
results: [expectedRegistrar]
});
assertEquals(expectedRegistrar.phonePasscode,
registry.util.parseForm('item').phonePasscode);
}
function testEdit() {
testView();
registry.testing.click($('reg-app-btn-edit'));
var form = document.forms.namedItem('item');
form.elements['newIp'].value = '1.1.1.1';
registry.testing.click($('btn-add-ip'));
form.elements['newIp'].value = '2.2.2.2';
registry.testing.click($('btn-add-ip'));
var exampleCert = $('exampleCert').value;
var exampleCertHash = '6NKKNBnd2fKFooBINmn3V7L3JOTHh02+2lAqYHdlTgk';
form.elements['clientCertificate'].value = exampleCert;
form.elements['failoverClientCertificate'].value = 'bourgeois blues';
registry.testing.click($('reg-app-btn-save'));
registry.testing.assertReqMockRsp(
test.testXsrfToken,
'/registrar-settings',
{op: 'update', args: {
clientCertificate: exampleCert,
clientCertificateHash: null,
failoverClientCertificate: 'bourgeois blues',
ipAddressWhitelist: ['1.1.1.1', '2.2.2.2'],
phonePasscode: expectedRegistrar.phonePasscode,
readonly: false }},
{status: 'SUCCESS',
message: 'OK',
results: [{}]});
// XXX: The response above is ignored as the page re-issues a fetch. Should
// either provide the real response here and use anyTimes(), or have
// resource_component use this directly.
expectedRegistrar.clientCertificate = exampleCert;
expectedRegistrar.clientCertificateHash = exampleCertHash;
expectedRegistrar.failoverClientCertificate = 'bourgeois blues';
expectedRegistrar.ipAddressWhitelist = ['1.1.1.1/32', '2.2.2.2/32'];
registry.testing.assertReqMockRsp(
test.testXsrfToken,
'/registrar-settings',
{op: 'read', args: {}},
{status: 'SUCCESS',
message: 'OK',
results: [expectedRegistrar]});
delete expectedRegistrar['clientCertificateHash'];
registry.testing.assertObjectEqualsPretty(
expectedRegistrar, registry.util.parseForm('item'));
}

View file

@ -0,0 +1,174 @@
// Copyright 2016 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
goog.setTestOnly();
goog.require('goog.dispose');
goog.require('goog.dom');
goog.require('goog.dom.classlist');
goog.require('goog.soy');
goog.require('goog.testing.MockControl');
goog.require('goog.testing.PropertyReplacer');
goog.require('goog.testing.asserts');
goog.require('goog.testing.jsunit');
goog.require('goog.testing.net.XhrIo');
goog.require('registry.registrar.ConsoleTestUtil');
goog.require('registry.soy.registrar.console');
goog.require('registry.testing');
goog.require('registry.util');
var $ = goog.dom.getRequiredElement;
var $$ = goog.dom.getRequiredElementByClass;
var stubs = new goog.testing.PropertyReplacer();
var test = {
testXsrfToken: '༼༎෴ ༎༽',
testClientId: 'testClientId',
mockControl: new goog.testing.MockControl()
};
function setUp() {
registry.testing.addToDocument('<div id="test"/>');
registry.testing.addToDocument('<div class="kd-butterbar"/>');
goog.soy.renderElement($('test'), registry.soy.registrar.console.main, {
user: {
id: 'test1.ui@example.com',
actionHref: 'blah',
actionName: 'omg'
},
xsrfToken: test.testXsrfToken,
clientId: test.testClientId
});
stubs.setPath('goog.net.XhrIo', goog.testing.net.XhrIo);
registry.registrar.ConsoleTestUtil.setup(test);
}
function tearDown() {
goog.dispose(test.console);
stubs.reset();
goog.testing.net.XhrIo.cleanup();
test.mockControl.$tearDown();
}
/** Creates a test registrar. */
function createTestRegistrar() {
return {
emailAddress: 'test2.ui@example.com',
clientIdentifier: 'theRegistrar',
ianaIdentifier: 1,
icannReferralEmail: 'lol@sloth.test',
whoisServer: 'foo.bar.baz',
referralUrl: 'blah.blar',
phoneNumber: '+1.2125650000',
faxNumber: '+1.2125650001',
localizedAddress: {
street: ['111 Eighth Avenue', 'Eleventh Floor', 'lol'],
city: 'New York',
state: 'NY',
zip: '10011',
countryCode: 'US'
}};
}
function testView() {
registry.registrar.ConsoleTestUtil.visit(test, {
path: 'whois-settings',
testXsrfToken: test.testXsrfToken,
testClientId: test.testClientId
});
var testRegistrar = createTestRegistrar();
registry.testing.assertReqMockRsp(
test.testXsrfToken,
'/registrar-settings',
{op: 'read', args: {}},
{
status: 'SUCCESS',
message: 'OK',
results: [testRegistrar]
});
var parsed = registry.util.parseForm('item');
parsed.ianaIdentifier = parseInt(parsed.ianaIdentifier);
registry.testing.assertObjectEqualsPretty(testRegistrar, parsed);
}
function testEdit() {
testView();
registry.testing.click($('reg-app-btn-edit'));
$('emailAddress').value = 'test2.ui@example.com';
$('localizedAddress.street[0]').value = 'look at me i am';
$('localizedAddress.street[1]').value = 'the mistress of the night';
$('localizedAddress.street[2]').value = '';
var parsed = registry.util.parseForm('item');
parsed.readonly = false;
registry.testing.click($('reg-app-btn-save'));
registry.testing.assertReqMockRsp(
test.testXsrfToken,
'/registrar-settings',
{op: 'update', args: parsed},
{
status: 'SUCCESS',
message: 'OK',
results: [parsed]
});
}
function testEditFieldError_insertsError() {
testView();
registry.testing.click($('reg-app-btn-edit'));
$('phoneNumber').value = 'foo';
var parsed = registry.util.parseForm('item');
parsed.readonly = false;
registry.testing.click($('reg-app-btn-save'));
var errMsg = 'Carpe brunchus. --Pablo';
registry.testing.assertReqMockRsp(
test.testXsrfToken,
'/registrar-settings',
{op: 'update', args: parsed},
{
status: 'ERROR',
field: 'phoneNumber',
message: errMsg
});
var msgBox = goog.dom.getNextElementSibling($('phoneNumber'));
assertTrue(goog.dom.classlist.contains(msgBox, 'kd-errormessage'));
assertTrue(goog.dom.classlist.contains($('phoneNumber'), 'kd-formerror'));
assertEquals(errMsg, goog.dom.getTextContent(msgBox));
}
function testEditNonFieldError_showsButterBar() {
testView();
registry.testing.click($('reg-app-btn-edit'));
var parsed = registry.util.parseForm('item');
parsed.readonly = false;
registry.testing.click($('reg-app-btn-save'));
var errMsg = 'One must still have chaos in oneself to be able to give ' +
'birth to a dancing star. --Nietzsche';
registry.testing.assertReqMockRsp(
test.testXsrfToken,
'/registrar-settings',
{op: 'update', args: parsed},
{
status: 'ERROR',
message: errMsg
});
assertEquals(errMsg, goog.dom.getTextContent($$('kd-butterbar-text')));
}

View file

@ -0,0 +1,159 @@
// Copyright 2016 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
goog.provide('registry.testing');
goog.setTestOnly('registry.testing');
goog.require('goog.asserts');
goog.require('goog.dom');
goog.require('goog.dom.classlist');
goog.require('goog.dom.xml');
goog.require('goog.events.EventType');
goog.require('goog.format.JsonPrettyPrinter');
goog.require('goog.json');
goog.require('goog.testing.asserts');
goog.require('goog.testing.events');
goog.require('goog.testing.events.Event');
goog.require('goog.testing.net.XhrIo');
/**
* Adds specified HTML string to document.
* @param {string} html
*/
registry.testing.addToDocument = function(html) {
goog.global.document.body.appendChild(
goog.dom.htmlToDocumentFragment(html));
};
/**
* Extracts XML document from inside an {@code <iframe>}.
* @param {string} xmlText
* @return {!Document}
*/
registry.testing.loadXml = function(xmlText) {
var xml = goog.dom.xml.loadXml(xmlText);
goog.asserts.assert(xml != null);
if ('parsererror' in xml) {
fail(xml['parsererror']['keyValue']);
}
return xml;
};
/**
* Extracts plain text string from inside an {@code <iframe>}.
* @param {string|!Document|!Element} want
* @param {string|!Document|!Element} got
*/
registry.testing.assertXmlEquals = function(want, got) {
assertHTMLEquals(registry.testing.sanitizeXml_(want),
registry.testing.sanitizeXml_(got));
};
/**
* Simulates a mouse click on a browser element.
* @param {!Element} element
*/
registry.testing.click = function(element) {
goog.testing.events.fireBrowserEvent(
new goog.testing.events.Event(
goog.events.EventType.CLICK, element));
};
/**
* Asserts {@code element} has 'shown' class.
* @param {!Element} element
*/
registry.testing.assertVisible = function(element) {
assertTrue('Element should have CSS "shown" class',
goog.dom.classlist.contains(element, 'shown'));
};
/**
* Asserts {@code element} has 'hidden' class.
* @param {!Element} element
*/
registry.testing.assertHidden = function(element) {
assertTrue('Element should have CSS "hidden" class',
goog.dom.classlist.contains(element, 'hidden'));
};
/**
* Like {@code assertObjectEquals} but with a better error message.
* @param {?Object} a
* @param {?Object} b
*/
registry.testing.assertObjectEqualsPretty = function(a, b) {
try {
assertObjectEquals(a, b);
} catch (e) {
throw Error(e.message + '\n' +
'expected: ' +
registry.testing.pretty_.format(a) + '\n' +
'got: ' +
registry.testing.pretty_.format(b));
}
};
/**
* JSON request/response simulator for {@code ResourceComponent} subclasses.
* @param {string} xsrfToken
* @param {string} path server resource path.
* @param {!Object} expectReqJson assert this object was sent,
* e.g. {'op':'read',{}}
* @param {!Object} mockRspJson mock a response, e.g. {'set':[]}
*/
registry.testing.assertReqMockRsp =
function(xsrfToken, path, expectReqJson, mockRspJson) {
var xhr = goog.testing.net.XhrIo.getSendInstances().pop();
assertTrue('XHR is active.', xhr.isActive());
assertEquals(path, xhr.getLastUri());
// XXX: XHR header checking should probably be added. Was inconsistent
// between admin and registrar consoles.
registry.testing.assertObjectEqualsPretty(
expectReqJson, goog.json.parse(xhr.getLastContent()));
xhr.simulateResponse(200, goog.json.serialize(mockRspJson));
};
/**
* Removes stuff from XML text that we don't want to compare.
* @param {string|!Document|!Element} xml
* @return {string}
* @private
*/
registry.testing.sanitizeXml_ = function(xml) {
var xmlString = goog.isString(xml) ? xml : goog.dom.xml.serialize(xml);
return xmlString
.replace(/^\s*<\?.*?\?>\s*/, '') // Remove declaration thing.
.replace(/xmlns(:\w+)?="[^"]+"/g, '') // Remove namespace things.
.replace(/>\s+</g, '><') // Remove spaces between XML tags.
.replace(/<!--.*?-->/, ''); // Remove comments.
};
/**
* JSON pretty printer.
* @type {!goog.format.JsonPrettyPrinter}
* @private
*/
registry.testing.pretty_ = new goog.format.JsonPrettyPrinter(
new goog.format.JsonPrettyPrinter.TextDelimiters());

View file

@ -0,0 +1,183 @@
// Copyright 2016 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
goog.setTestOnly();
goog.require('goog.dom.xml');
goog.require('goog.testing.asserts');
goog.require('goog.testing.jsunit');
goog.require('registry.testing');
goog.require('registry.xml');
function testEmptyElement_hasNoKeyValue() {
assertXmlTurnsIntoJson(
{'epp': {}},
'<epp></epp>');
}
function testSelfClosingRootElement_hasNoKeyValue() {
assertXmlTurnsIntoJson(
{'epp': {}},
'<epp/>');
}
function testElementWithWhitespaceTextContent_getsIgnored() {
assertXmlTurnsIntoJson(
{'epp': {}},
'<epp> \r\n </epp>');
}
function testElementWithTextContent_getsSetToKeyValueField() {
assertXmlTurnsIntoJson(
{'epp': {'keyValue': 'hello'}},
'<epp>hello</epp>');
}
function testTextWithSpacesOnSides_getsTrimmed() {
assertXmlTurnsIntoJson(
{'epp': {'keyValue': 'hello'}},
'<epp> hello </epp>');
}
function testAttribute_getsSetToFieldPrefixedByAtSymbol() {
assertXmlTurnsIntoJson(
{'epp': {'@ohmy': 'goth'}},
'<epp ohmy="goth"/>');
}
function testSingleNestedElement_keyIsNameAndValueIsNode() {
assertXmlTurnsIntoJson(
{'epp': {'ohmy': {'keyValue': 'goth'}}},
'<epp><ohmy>goth</ohmy></epp>');
}
function testMultipleNestedElements_valueBecomesArray() {
assertXmlTurnsIntoJson(
{'epp': {'ohmy': [{'keyValue': 'goth1'}, {'keyValue': 'goth2'}]}},
'<epp><ohmy>goth1</ohmy><ohmy>goth2</ohmy></epp>');
}
function testInterspersedText_throwsError() {
assertEquals(
'XML text "hello" interspersed with "there"',
assertThrows(function() {
registry.xml.convertToJson(
goog.dom.xml.loadXml(
'<epp> hello <omg/> there </epp>'));
}).message);
}
function testEppMessage() {
assertXmlTurnsIntoJson(
{
'epp': {
'@xmlns': 'urn:ietf:params:xml:ns:epp-1.0',
'response': {
'result': {
'@code': '1000',
'msg': {'keyValue': 'Command completed successfully'}
},
'resData': {
'domain:infData': {
'@xmlns:domain': 'urn:ietf:params:xml:ns:domain-1.0',
'domain:name': {'keyValue': 'justine.lol'},
'domain:roid': {'keyValue': '6-roid'},
'domain:status': {'@s': 'inactive'},
'domain:registrant': {'keyValue': 'GK Chesterton'},
'domain:contact': [
{'@type': 'admin', 'keyValue': '<justine>'},
{'@type': 'billing', 'keyValue': 'candycrush'},
{'@type': 'tech', 'keyValue': 'krieger'}
],
'domain:ns': {
'domain:hostObj': [
{'keyValue': 'ns1.justine.lol'},
{'keyValue': 'ns2.justine.lol'}
]
},
'domain:host': {'keyValue': 'ns1.justine.lol'},
'domain:clID': {'keyValue': 'justine'},
'domain:crID': {'keyValue': 'justine'},
'domain:crDate': {'keyValue': '2014-07-10T02:17:02Z'},
'domain:exDate': {'keyValue': '2015-07-10T02:17:02Z'},
'domain:authInfo': {
'domain:pw': {'keyValue': 'lolcat'}
}
}
},
'trID': {
'clTRID': {'keyValue': 'abc-1234'},
'svTRID': {'keyValue': 'ytk1RO+8SmaDQxrTIdulnw==-4'}
}
}
}
},
'<?xml version="1.0"?>' +
'<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">' +
' <response>' +
' <result code="1000">' +
' <msg>Command completed successfully</msg>' +
' </result>' +
' <resData>' +
' <domain:infData' +
' xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">' +
' <domain:name>justine.lol</domain:name>' +
' <domain:roid>6-roid</domain:roid>' +
' <domain:status s="inactive"/>' +
' <domain:registrant>GK Chesterton</domain:registrant>' +
' <domain:contact type="admin">&lt;justine&gt;</domain:contact>' +
' <domain:contact type="billing">candycrush</domain:contact>' +
' <domain:contact type="tech">krieger</domain:contact>' +
' <domain:ns>' +
' <domain:hostObj>ns1.justine.lol</domain:hostObj>' +
' <domain:hostObj>ns2.justine.lol</domain:hostObj>' +
' </domain:ns>' +
' <domain:host>ns1.justine.lol</domain:host>' +
' <domain:clID>justine</domain:clID>' +
' <domain:crID>justine</domain:crID>' +
' <domain:crDate>2014-07-10T02:17:02Z</domain:crDate>' +
' <domain:exDate>2015-07-10T02:17:02Z</domain:exDate>' +
' <domain:authInfo>' +
' <domain:pw>lolcat</domain:pw>' +
' </domain:authInfo>' +
' </domain:infData>' +
' </resData>' +
' <trID>' +
' <clTRID>abc-1234</clTRID>' +
' <svTRID>ytk1RO+8SmaDQxrTIdulnw==-4</svTRID>' +
' </trID>' +
' </response>' +
'</epp>');
}
/**
* Asserts {@code xml} turns into {@code json}.
* @param {!Object} json
* @param {string} xml
*/
function assertXmlTurnsIntoJson(json, xml) {
registry.testing.assertObjectEqualsPretty(
json, registry.xml.convertToJson(goog.dom.xml.loadXml(xml)));
}