toolkit/crashreporter/test/browser/browser_aboutCrashesResubmit.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 function cleanup_and_finish() {
     2   try {
     3     cleanup_fake_appdir();
     4   } catch(ex) {}
     5   Services.prefs.clearUserPref("breakpad.reportURL");
     6   gBrowser.removeTab(gBrowser.selectedTab);
     7   finish();
     8 }
    10 /*
    11  * check_crash_list
    12  *
    13  * Check that the list of crashes displayed by about:crashes matches
    14  * the list of crashes that we placed in the pending+submitted directories.
    15  */
    16 function check_crash_list(tab, crashes) {
    17   let doc = gBrowser.getBrowserForTab(tab).contentDocument;
    18   let crashlinks = doc.getElementById("tbody").getElementsByTagName("a");
    19   is(crashlinks.length, crashes.length,
    20     "about:crashes lists correct number of crash reports");
    21   // no point in checking this if the lists aren't the same length
    22   if (crashlinks.length == crashes.length) {
    23     for(let i=0; i<crashes.length; i++) {
    24       is(crashlinks[i].id, crashes[i].id, i + ": crash ID is correct");
    25       if (crashes[i].pending) {
    26         // we set the breakpad.reportURL pref in test()
    27         is(crashlinks[i].getAttribute("href"),
    28           "http://example.com/browser/toolkit/crashreporter/about/throttling",
    29           "pending URL links to the correct static page");
    30       }
    31     }
    32   }
    33 }
    35 /*
    36  * check_submit_pending
    37  *
    38  * Click on a pending crash in about:crashes, wait for it to be submitted (which
    39  * should redirect us to the crash report page). Verify that the data provided
    40  * by our test crash report server matches the data we submitted.
    41  * Additionally, click "back" and verify that the link now points to our new
    42  */
    43 function check_submit_pending(tab, crashes) {
    44   let browser = gBrowser.getBrowserForTab(tab);
    45   let SubmittedCrash = null;
    46   let CrashID = null;
    47   let CrashURL = null;
    48   function csp_onload() {
    49     if (browser.contentWindow.location != 'about:crashes') {
    50       browser.removeEventListener("load", csp_onload, true);
    51       // loaded the crash report page
    52       ok(true, 'got submission onload');
    53       // grab the Crash ID here to verify later
    54       CrashID = browser.contentWindow.location.search.split("=")[1];
    55       CrashURL = browser.contentWindow.location.toString();
    56       // check the JSON content vs. what we submitted
    57       let result = JSON.parse(browser.contentDocument.documentElement.textContent);
    58       is(result.upload_file_minidump, "MDMP", "minidump file sent properly");
    59       is(result.Throttleable, 0, "correctly sent as non-throttleable");
    60       // we checked these, they're set by the submission process,
    61       // so they won't be in the "extra" data.
    62       delete result.upload_file_minidump;
    63       delete result.Throttleable;
    64       // Likewise, this is discarded before it gets to the server
    65       delete SubmittedCrash.extra.ServerURL;
    67       for(let x in result) {
    68         if (x in SubmittedCrash.extra)
    69           is(result[x], SubmittedCrash.extra[x],
    70              "submitted value for " + x + " matches expected");
    71         else
    72           ok(false, "property " + x + " missing from submitted data!");
    73       }
    74       for(let y in SubmittedCrash.extra) {
    75         if (!(y in result))
    76           ok(false, "property " + y + " missing from result data!");
    77       }
    78       executeSoon(function() {
    79                     browser.addEventListener("pageshow", csp_pageshow, true);
    80                     // now navigate back
    81                     browser.goBack();
    82                   });
    83     }
    84   }
    85   function csp_fail() {
    86     browser.removeEventListener("CrashSubmitFailed", csp_fail, true);
    87     ok(false, "failed to submit crash report!");
    88     cleanup_and_finish();
    89   }
    90   browser.addEventListener("CrashSubmitFailed", csp_fail, true);
    91   browser.addEventListener("load", csp_onload, true);
    92   function csp_pageshow() {
    93     browser.removeEventListener("pageshow", csp_pageshow, true);
    94     executeSoon(function () {
    95                   is(browser.contentWindow.location, "about:crashes", "navigated back successfully");
    96                   let link = browser.contentDocument.getElementById(CrashID);
    97                   isnot(link, null, "crash report link changed correctly");
    98                   if (link)
    99                     is(link.href, CrashURL, "crash report link points to correct href");
   100                   cleanup_and_finish();
   101                 });
   102   }
   104   // try submitting the pending report
   105   for each(let crash in crashes) {
   106     if (crash.pending) {
   107       SubmittedCrash = crash;
   108       break;
   109     }
   110   }
   111   EventUtils.sendMouseEvent({type:'click'}, SubmittedCrash.id,
   112                             browser.contentWindow);
   113 }
   115 function test() {
   116   waitForExplicitFinish();
   117   let appD = make_fake_appdir();
   118   let crD = appD.clone();
   119   crD.append("Crash Reports");
   120   let crashes = add_fake_crashes(crD, 1);
   121   // we don't need much data here, it's not going to a real Socorro
   122   crashes.push(addPendingCrashreport(crD,
   123                                      crashes[crashes.length - 1].date + 60000,
   124                                      {'ServerURL': 'http://example.com/browser/toolkit/crashreporter/test/browser/crashreport.sjs',
   125                                       'ProductName': 'Test App',
   126                                       // test that we don't truncate
   127                                       // at = (bug 512853)
   128                                       'Foo': 'ABC=XYZ'
   129                                      }));
   130   crashes.sort(function(a,b) b.date - a.date);
   132   // set this pref so we can link to our test server
   133   Services.prefs.setCharPref("breakpad.reportURL",
   134                              "http://example.com/browser/toolkit/crashreporter/test/browser/crashreport.sjs?id=");
   136   let tab = gBrowser.selectedTab = gBrowser.addTab("about:blank");
   137   let browser = gBrowser.getBrowserForTab(tab);
   138   browser.addEventListener("load", function test_load() {
   139                              browser.removeEventListener("load", test_load, true);
   140                              executeSoon(function () {
   141                                            check_crash_list(tab, crashes);
   142                                            check_submit_pending(tab, crashes);
   143                                          });
   144                           }, true);
   145   browser.loadURI("about:crashes", null, null);
   146 }

mercurial