[Extenisons Bindings] Don't throw unchecked errors; add console errors

Throwing an unchecked runtime.lastError results in an uncaught
exception, which can prevent future JS from properly running in
somewhat unpredictable ways. These errors should be logged as console
errors, rather than being thrown as exceptions.

Add tests to a) check errors being logged and b) check that chaining
API calls and callbacks works even when there are uncheked last errors.

BUG=653596

Review-Url: https://codereview.chromium.org/2819683002
Cr-Commit-Position: refs/heads/master@{#465740}
diff --git a/extensions/renderer/module_system.cc b/extensions/renderer/module_system.cc
index bbc96f3..a1bb5098 100644
--- a/extensions/renderer/module_system.cc
+++ b/extensions/renderer/module_system.cc
@@ -61,20 +61,19 @@
 
   ExtensionsClient* client = ExtensionsClient::Get();
   if (client->ShouldSuppressFatalErrors()) {
-    console::AddMessage(context->GetRenderFrame(),
-                        content::CONSOLE_MESSAGE_LEVEL_ERROR, full_message);
+    console::AddMessage(context, content::CONSOLE_MESSAGE_LEVEL_ERROR,
+                        full_message);
     client->RecordDidSuppressFatalError();
   } else {
-    console::Fatal(context->GetRenderFrame(), full_message);
+    console::Fatal(context, full_message);
   }
 }
 
 void Warn(v8::Isolate* isolate, const std::string& message) {
   ScriptContext* script_context =
       ScriptContextSet::GetContextByV8Context(isolate->GetCurrentContext());
-  console::AddMessage(
-      script_context ? script_context->GetRenderFrame() : nullptr,
-      content::CONSOLE_MESSAGE_LEVEL_WARNING, message);
+  console::AddMessage(script_context, content::CONSOLE_MESSAGE_LEVEL_WARNING,
+                      message);
 }
 
 // Default exception handler which logs the exception.