Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(261)

Side by Side Diff: chrome/browser/extensions/api/README.txt

Issue 10388192: Initial unit tests for the discovery API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 This file describes steps and files needed when adding a new API to Chrome. 1 This file describes steps and files needed when adding a new API to Chrome.
2 Before you start coding your new API, though, make sure you follow the process 2 Before you start coding your new API, though, make sure you follow the process
3 described at: 3 described at:
4 http://www.chromium.org/developers/design-documents/extensions/proposed-change s/apis-under-development 4 http://www.chromium.org/developers/design-documents/extensions/proposed-change s/apis-under-development
5 5
6 Two approaches are available for writing your API specification. The original 6 Two approaches are available for writing your API specification. The original
7 approach relies on JSON specification files. The more recent and simpler system 7 approach relies on JSON specification files. The more recent and simpler system
8 uses Web IDL files, but does not yet support all the features of the JSON files. 8 uses Web IDL files, but does not yet support all the features of the JSON files.
9 Discuss with a member of the extensions team (aa@chromium.org) before you decide 9 Discuss with a member of the extensions team (aa@chromium.org) before you decide
10 which approach is better suited to your API. 10 which approach is better suited to your API.
11 11
12 The following steps suppose you're writing an experimental API called "Foo". 12 The following steps suppose you're writing an experimental API called "Foo".
13 13
14 -------------------------------------------------------------------------------- 14 --------------------------------------------------------------------------------
15 APPROACH 1: JSON FILES 15 APPROACH 1: JSON FILES
16 16
17 1) Write your API specification. 17 1) Write your API specification.
18 Create "chrome/common/extensions/api/experimental_foo.json". For inspiration 18 Create "chrome/common/extensions/api/experimental_foo.json". For inspiration
19 look at the "app" API. Include descriptions fields to generate the 19 look at the "app" API. Include descriptions fields to generate the
20 documentation. 20 documentation.
21 21
22 2) Add your API specification to the project. 22 2) Add your API specification to extensions_api_resources.grd.
23 Add an "<include ...>" line with your JSON specification file to 23 Add an "<include ...>" line with your JSON specification file to
24 "chrome/common/extensions_api_resources.grd". 24 "chrome/common/extensions_api_resources.grd".
25 25
26 3) Write the API function handlers. 26 3) Add your API specification to api.gyp.
27 Add "experimental_foo.json" to the "json_schema_files" section in
28 "chrome/common/extensions/api/api.gyp".
29
30 4) Write the API function handlers.
27 Create foo_api.cc and foo_api.h under "chrome/browser/extensions/api/foo". You 31 Create foo_api.cc and foo_api.h under "chrome/browser/extensions/api/foo". You
28 should use the JSON Schema Compiler. Look at the "alarms_api.cc" for details on 32 should use the JSON Schema Compiler. Look at the "permissions_api.cc" for
29 how to do that. 33 details on how to do that.
30 34
31 4) Register function handlers. 35 5) Register function handlers.
32 In "chrome/browser/extensions/extension_function_registry.cc" include foo_api.h 36 In "chrome/browser/extensions/extension_function_registry.cc" include foo_api.h
33 and instantiate a RegisterFunction for each function you created in (3). 37 and instantiate a RegisterFunction for each function you created in (3).
34 38
35 -------------------------------------------------------------------------------- 39 --------------------------------------------------------------------------------
36 APPROACH 2: IDL FILES 40 APPROACH 2: IDL FILES
37 41
38 1) Write your API specification. 42 1) Write your API specification.
39 Create "chrome/common/extensions/api/experimental_foo.idl". For inspiration look 43 Create "chrome/common/extensions/api/experimental_foo.idl". For inspiration look
40 at "alarms.idl". Include comments, they will be used to automatically generate 44 at "alarms.idl". Include comments, they will be used to automatically generate
41 the documentation. 45 the documentation.
42 46
43 2) Add your API specification to the project. 47 2) Add your API specification to api.gyp.
44 Add "experimental_foo.idl" to the "idl_schema_files" section in 48 Add "experimental_foo.idl" to the "idl_schema_files" section in
45 "chrome/common/extensions/api/api.gyp". 49 "chrome/common/extensions/api/api.gyp".
46 50
47 3) Write the API function handlers. 51 3) Write the API function handlers.
48 Create foo_api.cc and foo_api.h under "chrome/browser/extensions/api/foo". You 52 Create foo_api.cc and foo_api.h under "chrome/browser/extensions/api/foo". You
49 should use the JSON Schema Compiler. Look at the "alarms_api.cc" for details on 53 should use the JSON Schema Compiler. Look at the "alarms_api.cc" for details on
50 how to do that. 54 how to do that.
51 55
52 4) Nothing to do! Function handlers are automatically registered for you. 56 4-5) Nothing to do! Function handlers are automatically registered for you.
53 57
54 -------------------------------------------------------------------------------- 58 --------------------------------------------------------------------------------
55 STEPS COMMON TO BOTH APPROACHES 59 STEPS COMMON TO BOTH APPROACHES
56 60
57 5) Write support classes for your API 61 6) Write support classes for your API
58 If your API needs any support classes add them to 62 If your API needs any support classes add them to
59 "chrome/browser/extensions/api/foo". Some old APIs added their support classes 63 "chrome/browser/extensions/api/foo". Some old APIs added their support classes
60 directly to chrome/browser/extensions. Don't do that. 64 directly to chrome/browser/extensions. Don't do that.
61 65
62 6) Update the project with your new files. 66 7) Update the project with your new files.
63 The files you created in (3) and (5) should be added to 67 The files you created in (3) and (5) should be added to
64 "chrome/chrome_browser_extensions.gypi". 68 "chrome/chrome_browser_extensions.gypi".
65 69
66 -------------------------------------------------------------------------------- 70 --------------------------------------------------------------------------------
67 GENERATING DOCUMENTATION 71 GENERATING DOCUMENTATION
68 72
69 7) Build the project. (Only required if you used IDL files.) 73 8) Build the project. (Only required if you used IDL files.)
70 If you used IDL files, you need to build the project once in order for the 74 If you used IDL files, you need to build the project once in order for the
71 documentation to be properly generated. Do this now. (This is required in order 75 documentation to be properly generated. Do this now. (This is required in order
72 to generate the JSON file used to generate documentation.) 76 to generate the JSON file used to generate documentation.)
73 77
74 8) Add your JSON file to the documentation controller 78 9) Add your JSON file to the documentation controller
75 Open "chrome/common/extensions/docs/js/api_page_generator.js" and add a line 79 Open "chrome/common/extensions/docs/js/api_page_generator.js" and add a line
76 referring to "../api/experimental_foo.json". Do this even if you used the IDL 80 referring to "../api/experimental_foo.json". Do this even if you used the IDL
77 approach as this JSON file has been generated in (7). 81 approach as this JSON file has been generated in (7).
78 82
79 9) Write the static HTML page. 83 10) Write the static HTML page.
80 Write a small snippet of static HTML describing your API in 84 Write a small snippet of static HTML describing your API in
81 "chrome/common/extensions/docs/static/experimental.foo.html". For the moment, 85 "chrome/common/extensions/docs/static/experimental.foo.html". For the moment,
82 just include the following in this file, adjusting it to describe your API: 86 just include the following in this file, adjusting it to describe your API:
83 87
84 <div id="pageData-name" class="pageData">Experimental Foo APIs</div> 88 <div id="pageData-name" class="pageData">Experimental Foo APIs</div>
85 89
86 <!-- BEGIN AUTHORED CONTENT --> 90 <!-- BEGIN AUTHORED CONTENT -->
87 <p>The current methods allow applications to...</p> 91 <p>The current methods allow applications to...</p>
88 <!-- END AUTHORED CONTENT --> 92 <!-- END AUTHORED CONTENT -->
89 93
90 10) Build the documentation. 94 11) Build the documentation.
91 You will need to build DumpRenderTree once before you can build the 95 You will need to build DumpRenderTree once before you can build the
92 documentation. Once this is done, from "chrome/common/extensions/docs" run 96 documentation. Once this is done, from "chrome/common/extensions/docs" run
93 "build/build.py". For more information on building documentation see README.txt 97 "build/build.py". For more information on building documentation see README.txt
94 in "chrome/common/extensions/docs". 98 in "chrome/common/extensions/docs".
95 99
96 -------------------------------------------------------------------------------- 100 --------------------------------------------------------------------------------
97 WRITING TESTS 101 WRITING TESTS
98 102
99 TODO(beaudoin) 103 12) Write a unit test for your API.
100 104 Create "chrome/browser/extensions/api/foo/foo_api_unittest.cc" and test each of
105 your API methods. See "alarms_api_unittest.cc" for details. Once done add your
106 .cc to "chrome/chrome_tests.gypi".
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698