summaryrefslogtreecommitdiffstats
path: root/chrome/browser/resources/gaia_auth/test/content.js
blob: 459a5b059506edf2289e39c06f5ff3bda3d4cd13 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

console.log('Test script injected!');

function getQueryParam(key, defaultVal) {
  if (!defaultVal) defaultVal = '';
  key = key.replace(/[\[]/, '\\\[').replace(/[\]]/, '\\\]');
  var regex = new RegExp('[\\?&]' + key + '=([^&#]*)');
  var qs = regex.exec(window.location.href);
  if (qs == null)
    return defaultVal;
  else
    return qs[1];
}

if (document.URL.match(/https\:\/\/www\.google\.com\/accounts\/ServiceLogin/) ||
    document.URL.match(/https\:\/\/accounts\.google\.com\/ServiceLogin/) ||
    document.URL.match(
        /https\:\/\/gaiastaging\.corp\.google\.com\/ServiceLogin/) ||
    document.URL.match(/https\:\/\/insecure\.com\/accounts\/ServiceLogin/)) {
  var testEmail = unescape(getQueryParam('test_email'));
  var testPassword = unescape(getQueryParam('test_pwd'));
  console.log('Got test account info: ' + testEmail + '/' + testPassword);
  document.getElementById('Email').value = testEmail;
  document.getElementById('Passwd').value = testPassword;
  console.log('Form field changed!');
  if (testEmail != '') {
    document.getElementById('signIn').click();
    console.log('Form submitted!');
  }
}